Update item with same expiry
Hi patrickmn, We wanted to use in memory (fast) cache in golang to collect items from a running stream and use the item at the end of expiration as collected over time, approach we were using before was to create a cache and keep a channel ticking on time.After() on each key which went memory hungry, so using approach with go-cache where items expire after every X duration.
As such wanted to update item in cache with same expiry as original. So added function to do so ... would be happy to merge with upstream ...
I'm a little confused about this. Is the Update() method intended to keep the same expiration time as the original item? In that case, can't it just re-use the previous item's Expiration value?
While setting item in cache set() in needed internally and Set() in called externally, both of these take duration field which is either DefaultExpiration or the passed value,
now here the expiry to be set is new expiry time which would be x =[time which was set earlier - now ] so set() needs to be called with that difference x,
Set() calculates expiry as e = time.Now().Add(d).UnixNano() As we don't store when was an item set, so difference would be required to be calculated before an update,
Hence the use case.
Found this fork: https://github.com/arp242/zcache