FluentCache icon indicating copy to clipboard operation
FluentCache copied to clipboard

Cache not expiring

Open matishadow opened this issue 7 years ago • 1 comments

Most of the times the cache fails to expire in my code. Maybe you have an idea what I'm doing wrong. Any help would be greatly appreciated.

Here is the code directly using FluentCache: https://github.com/matishadow/GimmeDatAPI/blob/develop/GimmeDatAPI.Web/Controllers/ZascianekDataController.cs

And here is the GetZascianekExpireAfter method which result is passed to ExpireAfter. It aims to get TimeSpan which is remaining to 7 PM (19:00) https://github.com/matishadow/GimmeDatAPI/blob/develop/GimmeDatAPI.Cache/CacheInvalidation.cs

matishadow avatar Nov 20 '18 06:11 matishadow

Based on a quick look at your code it does seem like it should be working the way you intend.

What about writing a test case demonstrating the issue, without all the rest of the app code? It seems like a good test case would:

  1. setup a cached method with expiration set to 30 seconds in the future
  2. get the item & confirm it was retrieved from the cache by asserting that the cached item version = 0
  3. wait 5 seconds
  4. get the item again & confirm it was retrieved from the cache by asserting that the cached item version = 0
  5. wait the remaining time + some short buffer
  6. get the item again and confirm that the previous value expired by asserting that the cached item version = 1

A test case like the above demonstrating the issue would go a long way to figuring out what's not working properly.

evan-rash avatar Nov 20 '18 08:11 evan-rash