Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.cache by

It seems that the TTL cache should reset an item's TTL on a hit, similar
to how a hit on the LRU cache increases the recency of the item, however upon checking the code it is effectively a no-op. Is this intentional?

I have a branch with a fix that you are welcome to use if it isn't intentional, or I can go through the process of formally submitting a patch.

If it is intentional, should the hit behavior for all caches be no-ops? ie. it is especially surprising that a hit sometimes extends the life of an item (LRU cache) and sometimes doesn't (TTL cache)

1 Answer

0 votes

TTL is absolute and counts from when an item is inserted. Cache lookups (hits) should not affect the lifetime of a TTL item. If the cache has a TTL of 2 seconds and you insert X and then repeatedly look it up, it should still expire after 2 seconds.

The TTL cache is intended to be repeatedly refreshed so no items get more than the TTL time "stale" before that item is refreshed.

Alright, I will just re-`assoc` on lookup (which is I am currently doing). Thanks for the reply and clarification!