Hi,
First of all nice easy to use component, I was trying to set a sliding expiration when setting key value pairs in the memory cache and I noticed I couldn't get it work. I think the cause is the following:
The action MemoryCache_Set has two inputs, AbsoluteExpirationSeconds and SlidingExpirationSeconds, AbsoluteExpirationSeconds is mandatory and SlidingExpirationSeconds is not mandatory.
It appears that you're unable to set SlidingExpirationSeconds because of the mandatory settings in combination with the following code:
I think the check should be so that only one parameter has a value and never both or none instead of the current situation where AbsoluteExpirationSeconds is mandatory and can't be 0.
Could the forge component be updated so that it facilitates sliding expiration? Or if I'm wrong could somebody explain how I can set the sliding expiration?
Thanks!
Hi Lars!
Thanks for bringing this up.
Sliding expiration is a cache strategy that extends the validity of the cached variable by a specific duration every time it is accessed before it expires. Unlike fixed (absolute) expiration, which kills the variable at a specific time regardless of activity. The reason the absolute expiration is mandatory is that we need to ensure the cache will expire at some point, regardless of whether it is kept active. It is possible (and you should) use both absolute and sliding expiration, but the first must not be set to zero to avoid the cache never expiring. To persist this value for a longer time, you can always set the AbsoluteExpirationSeconds parameter to a large value (enough to fulfil your usecase), but I strongly recommend giving your cache a finite lifespan.
I hope this clarifies your question.
Hi André,
Thank you for your prompt response and explanation about the sliding expiration.
When I try setting both the sliding and absolute expiration with the MemoryCache_Set action I get the following exception:
So when using sliding expiration DateTimeOffset.MaxValue is expected for AbsoluteSlidingExpiration. However the code always does:
I appears that I can't set AbsoluteExpirationSeconds to a valid value so that I can use SlidingExpirationSeconds.I hope this clarifies the problem I'm running into.
Hi Lars,
OK, I've got it. It's much clearer now. It does seem to be a bug. Both absolute and sliding expiration parameters are supposed to be allowed. Perhaps this changed in the last update. I'll check and make this fix available in the next release.
Thank you again for your contribution on bringing this to our attention.