go-cache
go-cache copied to clipboard
best way to extend time on an not expired object?
is there a helper function?
It would be great to have complementary Increment and Decrement methods that refresh the expiration. Unfortunately, it's not safe to do a Replace(Get(), ...) as that would be a race (another goroutine could change the value between the time the Get() and the Replace() happens).
Perhaps just a new method to UpdateExpiration on a key would be sufficient, here? You could pass a time, or DefaultExpiration, or NoExpiration as appropriate. So:
func (c Cache) UpdateExpiration(k string, d time.Duration)
Related: PR #20.
Any update on this one? Is the project dead?
As far as I know Patrick is no longer maintaining this @g-rad; I made a compatible fork which adds some commonly requested features over here: https://github.com/zgoat/zcache
v1 is designed to remain compatible with go-cache; so you can use it as a drop-in replacement. It adds Touch() to update expiry times.