# Failed to write to cache with TTL

**URL:** <https://discuss.dgraph.io/t/failed-to-write-to-cache-with-ttl/13421>\
**Category:** Ristretto\
**Tags:** kind:question\
**Created:** [March 26, 2021, 6:32pm UTC](https://discuss.dgraph.io/t/failed-to-write-to-cache-with-ttl/13421 "2021-03-26T18:32:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![linih](https://avatars.discourse-cdn.com/v4/letter/l/e480ec/32.png) [@linih](https://discuss.dgraph.io/u/linih)\
**Post date:** [March 26, 2021, 6:32pm UTC](https://discuss.dgraph.io/t/failed-to-write-to-cache-with-ttl/13421/1 "2021-03-26T18:32:19Z")

</div>

I am using ristretto cache as shown in the official example, but the get operation failed frequently. I think my example entry was not not successfully written to cache (instead of being evicted). Is there any specific settings to make sure “writing to cache” always succeed?

I am trying out the following code:

```auto
	cache, _ := ristretto.NewCache(&ristretto.Config{
		NumCounters: 1e6, // Num keys to track frequency of (1M).
		MaxCost: 1 << 26, // Maximum cost of cache (64MB).
		BufferItems: 64, // Number of keys per Get buffer.
	})
	cache.SetWithTTL("key", "value", 1, 600*time.Second) // set a value
	// wait for value to pass through buffers
	time.Sleep(10 * time.Millisecond)

	value, found := cache.Get("key") <<< FAILURE 

```

---

<div class="post-metadata">

**Author:** ![linih](https://avatars.discourse-cdn.com/v4/letter/l/e480ec/32.png) [@linih](https://discuss.dgraph.io/u/linih)\
**Post date:** [March 26, 2021, 7:17pm UTC](https://discuss.dgraph.io/t/failed-to-write-to-cache-with-ttl/13421/2 "2021-03-26T19:17:06Z")

</div>

ok, seems I need to increase the delay to ensure the values are passed through buffers
