A collective least-recently used cache.
Excellent article about Magazine:
Here is the basic usage.
// create a cachevar Cache = require'magazine'var cache =// create a magazine that stores to the cachevar magazine = cachecreateMagazine// hold and release to key/value pairs to get them into the magazinemagazinehold'one' number: 1 releasemagazinehold'two' number: 2 release// wait a secondsetTimeoutafterOneSecond 1000// after a second hold and release one of the keys to refresh itmagazinehold'one' nullrelease// wait another secondsetTimeoutafterTwoSeconds 1000// after two seconds, purge anything that is older than a second and a halfcacheexpireDatenow - 1500// hold the one cartidge, the given value is the default value to use if the// value does not exist in the cache.var cartridge = magazinehold'one' number: null// check for a cache hit on oneif cartridgevaluenumber == nullconsole.log'one is not in cache'cartridgeremoveelseconsole.log'one is in cache'cartridgereleasecartridge = magazinehold'two' number: null// check for a cache hit on twoif cartridgevaluenumber == nullconsole.log'two is not in cache'cartridgeremoveelseconsole.log'two is in cache'cartridgerelease
Create a new cache.
Purge the cache removing items before the given date.
Create an iterator over the cache in least recently used order.
Create a magazine using the cache.
Expire only the items in the current magazine.
Hold a cartridge for the given key creating a cartridge if one does not exist.
Release the hold on the cartridge.
Remove the hold the cartridge. You must be the only one holding it to remove it.
Adjust the heft of the cartridge. Heft is some arbitrary measure of the weight of cartridge. For cached managed by count, the actual count of items might not be a the cache entry itself. The cache entry could contain an array of items, for example, and user wants to purge the cache when it has more than a total number of items.
An arbitrary measure of the weight of the cartridge.
Move to the next oldest entry in the queue.
Releases a cartridge if one is held, a safe way to finalize a purge iteration.