I'd like to be able to change an item's life span after adding it.
In my case I want to have it so:
An user interacts with my application
I look for them in the cache, if they're not present I get them from a database.
Make sure they stay in memory while I need them (which can take an arbitrary amount of time)
... (my program)
After I'm done, set it so they expire in 60 seconds unless the user interacts (which would take us back to the first step).
Right now this can be done by:
Looking for them in the cache. And if they're not present I get them BUT save it outside the cache.
... (my program)
After I'm done, If they were in the cache and still are, remove them.
Add them to the cache with a life span of 60 seconds.
This adds a lot of complexity which would be solved by being able to change the items life span (first to 0 and then to 60).
Issue implementing it
I tried implementing it by adding a method to CacheItem (you can see it here), but came across an issue if you:
Create an item with a life span
Set it to 0
Wait until the next expirationCheck (here it stops running because there's no items with lifespan != 0)
Set it to any value different than 0
Now it will never expire because the expirationCheck stopped running
This issue is the reason the test currently doesn't pass.
If I run table.expirationCheck() after resetting the life span it works as expected, but currently there's no way to do it from the method.
I'd like to be able to change an item's life span after adding it.
In my case I want to have it so:
Right now this can be done by:
This adds a lot of complexity which would be solved by being able to change the items life span (first to 0 and then to 60).
Issue implementing it
I tried implementing it by adding a method to CacheItem (you can see it here), but came across an issue if you:
This issue is the reason the test currently doesn't pass. If I run
table.expirationCheck()
after resetting the life span it works as expected, but currently there's no way to do it from the method.