ttlcache
ttlcache copied to clipboard
Enhancement Req - Add option to the cache to prevent updates when using Set()
Use case: I use the cache to capture data i receive over UDP. In some cases, i have competing producers that will send the same information for a Key. I want the first message to win and be the one persisted in the cache and not have further messages overwrite.
Looking at the cache.set() function, it searches for an existing element and overwrites it. https://github.com/jellydator/ttlcache/blob/master/cache.go#L134-L142
I would like a new option for the cache set on creation to prevent overwrites
cache := ttlcache.New[string, string](
ttlcache.WithTTL[string, string](30 * time.Minute),
ttlcache.WithoutOverwrite(),
)
//Pseudo-code to show the expectation
cache.Set("first", "value1", ttlcache.DefaultTTL)
cache.Set("first", "value2", ttlcache.DefaultTTL)
cache.Set("first", "value3", ttlcache.DefaultTTL)
v:= cache.Get("first").Value()
assert.Equal(t, "value1",v)
@swithek I PR'd against master. I assume master is tracking to v3
(that's the version I'm using in my project)
@ReneKroon is this a PR you could review?
Currently on holiday, will check back in in August
Op wo 27 jul. 2022 03:07 schreef Patrick Picard @.***>:
@ReneKroon https://github.com/ReneKroon is this a PR you could review?
— Reply to this email directly, view it on GitHub https://github.com/jellydator/ttlcache/issues/78#issuecomment-1196157554, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW5D6GXVI7ULE6L5LACJ3LVWCDWFANCNFSM54DPAADA . You are receiving this because you were mentioned.Message ID: @.***>
closed PR and closing issue. Code remains on fork.