Allow ttl to be set for a key on cache miss

Description

Create a second arity for miss that takes an options map. In the TTLCache implementation use the :ttl key from the options to set a non-default ttl for a cache object. All other implementations will disregard the options and call the original version of miss.

Environment

None

Activity

Show:
Sean Corfield
June 9, 2019, 1:18 AM

I've thought about this a lot. It's an interesting enhancement but it would require a lot of changes and would introduce performance overhead and complexity so I'm not willing to add it to the current TTL cache.

If you feel inclined to submit a patch (after signing the CLA), that adds a completely new TTL cache variant that supports this, I might take another look at it.

Sean Corfield
March 1, 2018, 6:45 AM

Definitely an interesting enhancement to the basic TTLCache. It would require that each item be stored with both its creation time and its own TTL, and therefore a miss would have to scan the entire keyset to evict expired items (since each one can expire at a different time). The current TTLCache actually suffers from that performance problem already – see – so it wouldn't be any worse than that.

You wouldn't be able to use this new miss call via through, so it also has that disadvantage.

import
October 10, 2014, 10:55 PM

Here's the use case that motivated this:

We want to store oauth tokens so that we do not constantly have to make service calls to verify the token. The response on this service call has the expiration time of the token. We want to set our ttl to expire when the oauth token expires.

Won't Fix

Assignee

Sean Corfield

Reporter

import

Labels

None

Approval

None

Patch

Code and Test

Priority

Major