ASP.NET have a nice caching feature, how do I best apply same logic to this scenario? This is a background application – not a web-something. I want to get and return the cached object from memory, instead of repeating requests from database. Only the first request per each unique match of the parameters c, a and cu should invoke the database. Let say, per 6 hours.
The constructor take three parameters and serves as a setter for three lists. The constructor recieves a neat collection of 0-300 strictly choosen rows of data. Though, with a tensing amount of requests.
(Please note that the sample and namings are pseudo)
/// <summary>
/// Constructor
/// </summary>
public Collect(string c, string a, string cu)
: base(c, a, cu)
{
db = new DatabaseInstance();
// DObject
this._d = (from d in db.DObject
where ....
select d).ToList();
// SObject
this._s = (from s in db.SObject
where ......
select s).ToList();
// MObject
this._v = (from mv in db.MObject
where ......
select mv).ToList();
}
You can use the
System.Runtime.Caching.MemoryCacheobject for that. It works almost the same way asSystem.Web.Cachingworks but is available without references toSystem.Weband is a lot more extendable.