go-cache icon indicating copy to clipboard operation
go-cache copied to clipboard

best way to extend time on an not expired object?

Open dabba39 opened this issue 8 years ago • 4 comments

is there a helper function?

dabba39 avatar Aug 04 '17 08:08 dabba39

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)

dossy avatar Aug 23 '17 17:08 dossy

Related: PR #20.

dossy avatar Aug 23 '17 18:08 dossy

Any update on this one? Is the project dead?

glebteterin avatar Dec 23 '20 00:12 glebteterin

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.

arp242 avatar Dec 23 '20 06:12 arp242