Team,
I’m making an app where I have to save data in db and ristretto as well. Does ristretto fires any event on ttl expiration of an object. It would be easier to manage the db in parallel.
Especially in oauth servers this is needed.
@mrjn , @ibrahim . I would be grateful if you can suggest here.
dmai
(Daniel Mai)
January 27, 2021, 9:24pm
2
You can set a func for OnEvict
which gets called every time a cached key gets evicted (like when a TTL expires). GitHub - dgraph-io/ristretto: A high performance memory-bound Go cache
Oops. sorry I just missed that. Thanks a lot for help.
Sorry for being little lazy but just a quick question, consider I save string type key values in ristretto
key=“Name”
Value=“Daniel”
Cost=1
As per this definition, func(hashes [2]uint64, value interface{}, cost int64)
, what will be the value of these parameters:
hashes array and value
ibrahim
(Ibrahim Jarif)
January 29, 2021, 10:11am
4
@smartaquarius10 looks like our readme is out of date. You’ll have to set the OnEvict
function which accepts an *ristretto.Item
See this for an example of how to use it
c, err := NewCache(&Config{
NumCounters: 100,
MaxCost: 10,
BufferItems: 64,
IgnoreInternalCost: true,
Cost: func(value interface{}) int64 {
return int64(value.(int))
},
OnEvict: func(item *Item) {
m.Lock()
defer m.Unlock()
evicted[item.Key] = struct{}{}
},
})
Hey @ibrahim ,
Thanks a lot for sharing. This one what I wanted so that I can remove the same value from my actual storage DB.
Thank you
1 Like