Replies: 2 comments 1 reply
-
I've ended up improving performance elsewhere in my code that has improved LazyCache performance to the point that I don't seem to need the factory timeout any more, so less need for Fusion Cache. |
Beta Was this translation helpful? Give feedback.
-
Hi @tjmoore , and thanks for considering FusionCache!
Yep: conditional refresh is still a refresh, and a refresh happens only when Duration expires, otherwise it would not be a cache.
That is normally know as microcaching, and it usually works great.
The situation as described is quite strange and not that clear to me honestly, I would need to understand more.
Is LastUpdate the last update of the file, somehow obtained externally from the cache, maybe via a watcher?
How do you know that the database is changed?
Interesting, why the different approach with LazyCache?
Because there's no soft timeout support, I suppose.
Same as above: because there's no soft timeout support.
But as said with a different approach, right?
Honestly: if you're happy with LazyCache and don't need the extra features of FusionCache, by all means stay with LazyCache. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement Conditional Refresh based on a modified timestamp. For example on a file based database where if the file has been modified then I want the cache to update fairly quickly, otherwise return the last cached value.
However it seems the conditional refresh check only occurs when the Duration expires. Therefore if I set Duration to say 2 minutes, it won't check the database for modified until 2 minutes has expired.
I can set Duration to a shorter value like a second or two, and it will regularly run the conditional check, though I seem to be hitting performance issues under load. Noting that the database can change frequently (between every 10 to 30 seconds) and some of the cache factory operations can take a few seconds. I've got
FailSafe
on andFactoryTimeout
at 200ms to handle long factory cache time and expecting anything longer to cache in the background and caller gets the last cached value. However I'm seeing my load tests back up and responses can increase greatly over time and I start getting thread pool starvation.Perhaps because the Duration is short makes every caller wait for a fresh cache value instead of getting stale value when returning
NotModified()
?For example:
(where
LastUpdate
is aDateTimeOffset
property,key
is the cache key andaddItemFactory
is the factory method to call)My tests are complicated to show, but they're simulating hundreds of concurrent requests on an API every few seconds, combined with background updates to the database.
Basically I need response times on the API to be as fast as possible and not delayed by cache entries being rebuild from factory, but cache to update in the background relatively frequently if database has known to be changed.
I've compared this vs LazyCache where I have a crude modified check before calling the cache method and I remove the key from the cache if known to be modified so it forces re-cache. This works with LazyCache and I get less pile-up on the load test, but response time average can increase for a while each time something invalidates and the factory methods have to run. The response times are a bit too slow for the API still.
i.e. LazyCache performs better but it's not ideal which is why I'm looking at FusionCache, but I'm not quite getting the performance I want.
The ideal is to sort out the slow factory methods in my code, but then with the background caching and maybe the cache stampede protection in FusionCache I'd expect it to be less of an issue and not impact on API response times.
Beta Was this translation helpful? Give feedback.
All reactions