galaxycache
galaxycache copied to clipboard
*: add TTL support
Add TTL support for keys. Implemented for our use case in https://github.com/thanos-io/thanos/ where cached data can potentially change over time. Thus, some kind of TTL mechanism is needed. Implemented it in the same fashion as https://github.com/mailgun/groupcache - deadline for keys is embedded in the value in the LRU cache. On retrieval, the deadline is checked and we are past it then we remove that key.
In HTTP the expiry date is exposed via an extra header. With gRPC, a new field has been added.
Note: this implies that users will have a somewhat synchronized time across nodes in the group. Otherwise, extra fetches might happen or the keys might not ever expire.
cc @akanshat
Thank you for your thorough review, we will try the epochs approach and come back to you.