In my project, we use web services to retrieve data from the database and populate data from web services into the cache. I use Absolute expiration and the duration is 4 hours. Thus, after 4 hours, the cache expires, and therefore the web service is called to refill the data in the cache.
Now the problem is this:
Sometimes there is the problem of establishing a connection between the web services and the database, and therefore the web services do not return data.
In this case, the cache is filled with zero values ββfor all fields and the cache is up to 4 hours (before the expiration date), it is not populated.
I am looking for two types of solutions: 1) we can update the cache before it expires, and then call the web service. If the web service returns data, overwrite the cache. 2) the cache never expires, and each so often we create a thread that updates the cache if we return the data.
But I'm not sure how to implement the above solutions? Can someone let me understand the technical part? Thanks for the help!
MY current fill cache code:
ctx.Cache.Insert("cachename", cacheValue, null, DateTime.Now.AddHours(Int32.Parse(siteViewModel.ApplicationSettings["CacheDurationHours"])), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null );
source share