memoise
memoise copied to clipboard
caching strategies and key invalidation
By using ...
of memoise
, one can have a full cache invalidation, if I understand well. Meaning: when the result of ...
(function) is different, the value is recalculated (I hope I'm right, the docs are a bit vague)
Anyway, having a more fine-grained memoization would be nice. Meaning: for example, the timeout
function is for full cache invalidation. Having a key-specific invalidation makes more sense to me, so that one key is removed from the cache if it's not valid anymore.
Invalidating a key can be based on different cache strategies (or even any combination thereof). I'm thinking about many, and this may be extensible: 'first in first out' (with max number of keys), 'time to live' (max time) , 'max time idle' (max time not used), 'least recently used' (max number of keys), 'least frequently used' (max number of keys), ... .
It's more a thought/idea, but it be really cool to have this...
In addition, being able to explicitly invalidate a single key at user's request is useful: e.g. retry a network resource within a memoised function eventually gives a 404, or whatever, and at this point I would want to invalidate that particular memoised function call, so I can try again in the future, not returned the error response from the cache.