package
Set Associative Cache
npm install sacjsGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Generic n-way Set Associative Cache for node.js.
npm install sacjsvar Cache = require('sacjs');
var cache = new Cache({ assoc: 4, size: 10000, algorithm: 'lru' });
cache.put(key, data);
// ...
var data = cache.get(key);
// ...
cache.del(key);
// ...
cache.clear();key used to store data in the cache can be any scalar or object/array. You can supply serialize option that will be used to convert keys to strings, otherwise json-stable-stringify will be used. Serialized keys are hashed using Dan Bernstein's algorithm.
Options object is passed to cache constructor.
assoc - cache associativity level (the number of slots per set). For any given key an item can be stored in any of the slots in the set. Higher associativity improves hit ratio but reduces cache performance.
size - cache size (the number of sets of slots the cache will store). The total number of items the cache can store is assoc * size
algorithm - eviction algorithm. Can be:
created, accessed (passed the slot) and evict (passed the set - the hash of slots). Implementations of eviction algorithms are in algorithms.js and cache.spec.js.serialize - custom key serialization algorithm. Should return the same string for the same key every time it is called. By default, json-stable-stringify is used. Pass false to skip serializing (if all keys are strings or numbers).
Cache usage statistics are available in stat property of the cache instance. The stat object has the following properties:
Estimated unpacked size across 11 packages.
209.4 kB
Includes dependencies.