Closed varun06 closed 4 years ago
That's by design. Writing the values immediately would negatively affect the concurrency of the cache. Ristretto first sends the new values to a buffer. Only when the buffer is full the entries are added to the cache's storage (or rejected, if the LFU policy rejects them).
That's the reason that our tests sleep for a little before verifying the chache. It's ok to do so in your own tests.
Blog article with more details: https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/
Note that Caffeine always writes to the map first, then async writes to the eviction policy. However we're fortunate to have a high performance concurrent hash table, which offers (roughly) per-entry locking. I believe this was chosen due to the poor performance of Go's, so the team optimized for DGraph's specific needs which allowed for this for improved write throughput.
Thanks for clarifying.
I have some tests where I set a value and then try to get it immediately. But cache reports that value is not avalable. If I add
time.Sleep(100 * time.MilliSecond)
, it works. I have also seen same pattern in ristretto tests https://github.com/dgraph-io/ristretto/blob/master/cache_test.go#L346.Is there a particular reason that values are not available immediately??