I am calling the following every 10 seconds as a test:-
var cache = _cacheManager.GetCache("PendingTasksCache");
return _cacheManager
.GetCache("PendingTasksCache")
.Get("pendingtaskscount", () =>
GetPendingTasksCountQuery());
Which in turn calls this:-
private int GetPendingTasksCountQuery()
{
return _ticketRepository.Count(x => x.Status == "Pending")
+ _changeRequestRepository.Count(x => x.Status == "Pending")
+ _contractRepository.Count(x => x.Status == "Pending")
+ _orderRepository.Count(x => x.Status == "Pending");
}
And the cache itself is set like this for a 30 second window ( as a test):-
Configuration.Caching.Configure("PendingTasksCache", cache =>
{
cache.DefaultSlidingExpireTime = TimeSpan.FromSeconds(30);
});
The first time it is called, it fetches the data successfully. But I would expect it to refresh the cache and rebuild the data every 30 seconds. But it never does and never calls GetPendingTasksCountQuery again. Where am I going wrong or what have I misunderstood?
5 Answer(s)
-
0
Anyone? I'll give you a chocolate biscuit
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Did you solve your problem ? Your usage seems fine but why do you have the first line ?
var cache = _cacheManager.GetCache("PendingTasksCache");Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Isn't the definition of a "sliding cache" is that it doesn't recalculate data until it hasn't been accessed for the "slidingTimeExpiration" ?
If it's set to 30s and you're accessing it every 10s, it will never recalculate data.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Ah ok - so I am missing something. I was hoping to use it to store that data for an amount of time and prevent frequent slow queries during that time, retrieving from cache instead. Therefore, I guess it is the AbsoluteExpireTime I should be using instead?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I guess it suits your needs more than the Sliding type. Remember that the cache will expire the entry after the amount of time you setted, even if no access happend.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)