# Does ristretto fires event when ttl expires

**URL:** <https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499>\
**Category:** Ristretto\
**Tags:** kind:question, ristretto\
**Created:** [January 27, 2021, 9:17pm UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499 "2021-01-27T21:17:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![smartaquarius10](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@smartaquarius10](https://discuss.dgraph.io/u/smartaquarius10)\
**Post date:** [January 27, 2021, 9:17pm UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499/1 "2021-01-27T21:17:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmai](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dmai/32/1254_2.png) [@dmai](https://discuss.dgraph.io/u/dmai)\
**Post date:** [January 27, 2021, 9:24pm UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499/2 "2021-01-27T21:24:07Z")

</div>

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](https://github.com/dgraph-io/ristretto#Config)

---

<div class="post-metadata">

**Author:** ![smartaquarius10](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@smartaquarius10](https://discuss.dgraph.io/u/smartaquarius10)\
**Post date:** [January 28, 2021, 7:18pm UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499/3 "2021-01-28T19:18:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ibrahim](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ibrahim/32/6387_2.png) [@ibrahim](https://discuss.dgraph.io/u/ibrahim)\
**Post date:** [January 29, 2021, 10:11am UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499/4 "2021-01-29T10:11:10Z")

</div>

@smartaquarius10 looks like our readme is out of date. You’ll have to set the `OnEvict` function which accepts an `*ristretto.Item`

> <https://github.com/dgraph-io/ristretto/blob/b1486d8516f2a911714d62a50c32b9a0ce5d0287/cache.go#L113-L115>

See this for an example of how to use it

> <https://github.com/dgraph-io/ristretto/blob/b1486d8516f2a911714d62a50c32b9a0ce5d0287/cache_test.go#L220-L233>

---

<div class="post-metadata">

**Author:** ![smartaquarius10](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@smartaquarius10](https://discuss.dgraph.io/u/smartaquarius10)\
**Post date:** [February 2, 2021, 7:09pm UTC](https://discuss.dgraph.io/t/does-ristretto-fires-event-when-ttl-expires/12499/5 "2021-02-02T19:09:43Z")

</div>

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 🙂
