tiny-fifo
v1.2.0
Published
Tiny FIFO cache for Client or Server
Downloads
28
Maintainers
Readme
tiny-fifo
Tiny FIFO cache for Client or Server
const cache = fifo(max, ttl = 0);
clear
Method
Clears the contents of the cache
return {Object} FIFO instance
Example
cache.clear();
delete
Method
Removes item from cache
param {String} key Item key
return {Object} FIFO instance
Example
cache.delete("myKey");
evict
Method
Evicts the first item from cache
return {Object} FIFO instance
Example
cache.evict();
get
Method
Gets item in cache
param {String} key Item key
return {Mixed} Undefined or Item value
Example
const item = cache.get("myKey");
keys
Method
Returns an Array
of cache item keys
return {Array} Array of keys
Example
console.log(cache.keys());
max
Property
Max items to hold in cache (1000)
Example
const cache = fifo(500);
cache.max; // 500
set
Method
Sets item in cache
param {String} key Item key
param {Mixed} value Item value
return {Object} FIFO instance
Example
cache.set("myKey", {prop: true});
size
Property
Number of items in cache
Example
const cache = fifo();
cache.size; // 0 - it's a new cache!
ttl
Property
Milliseconds an item will remain in cache; lazy expiration upon next get()
of an item
Example
const cache = fifo();
cache.ttl = 3e4;
License
Copyright (c) 2019 Jason Mulligan Licensed under the BSD-3 license.