core.cache

Allow ttl to be set for a key on cache miss

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

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.

Activity

Hide
Patrick Gombert added a comment -

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.

Show
Patrick Gombert added a comment - 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.
Hide
Sean Corfield added a comment -

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 CCACHE-15 – 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.

Show
Sean Corfield added a comment - 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 CCACHE-15 – 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: