locking-cache
I am a locking LRU cache. This means that subsequent calls to a cached function will wait until the initial call has populated the cache, at which point all pending calls will be provided with cached data.
Usage
var lockingCache = lockedFetch = ; var fetch = ; // will trigger the initial fetch; // will wait for the initial fetch to complete (or fail);
See lru-cache
for cache options.
The dispose
option that's passed to the underlying LRU differs slightly from
what lru-cache
documents, as values are stored as arrays in order to support
varargs (multiple values passed to unlock()
):
var lockedFetch =
A custom factory function (that returns an LRU
instance or compatible) may be
provided as the last argument. Here are 2 examples of how it can be used.
var lockingCache = lockedFetchA = lockedFetchB = ; // ...