jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
883 stars 115 forks source link

Strange issue with OnEviction/OnInsertion hooks #123

Closed Snawoot closed 4 weeks ago

Snawoot commented 4 months ago

It seems under some circumstances single key can be present in cache twice, or at least have a duplicate in expiration queue.

It happens like this:

  1. Some keys get added to cache, some get updated to extend their TTL.
  2. I dump cache content periodically and see item will be valid, for example, for 10 more seconds.
  3. After, for example, 5 seconds OnEviction hook fires for that element.
  4. I prolong key for 10 more seconds immediately.
  5. Apparently some "lost" key gets prolonged and early OnEviction happens again even tho Item in cache is supposed to expire later.

It feels like in some place which works with expiration queue is not synchronized with storage update and/or duplicate item gets into expiration queue.

I'm using v3.1.1. Unfortunately, that's as much details I can provide, I triggered this issue only in prod environment and didn't managed to reproduce it locally.