Tiny FIFO cache for Client or Server
npm install tiny-fifojavascript
const cache = fifo(max, ttl = 0);
`
clear
$3
Clears the contents of the cache
return {Object} FIFO instance
Example
`javascript
cache.clear();
`
delete
$3
Removes item from cache
param {String} key Item key
return {Object} FIFO instance
Example
`javascript
cache.delete("myKey");
`
evict
$3
Evicts the first item from cache
return {Object} FIFO instance
Example
`javascript
cache.evict();
`
get
$3
Gets item in cache
param {String} key Item key
return {Mixed} Undefined or Item value
Example
`javascript
const item = cache.get("myKey");
`
keys
$3
Returns an Array of cache item keys
return {Array} Array of keys
Example
`javascript
console.log(cache.keys());
`
max
$3
Max items to hold in cache (1000)
Example
`javascript
const cache = fifo(500);
cache.max; // 500
`
set
$3
Sets item in cache
param {String} key Item key
param {Mixed} value Item value
return {Object} FIFO instance
Example
`javascript
cache.set("myKey", {prop: true});
`
size
$3
Number of items in cache
Example
`javascript
const cache = fifo();
cache.size; // 0 - it's a new cache!
`
ttl
$3
Milliseconds an item will remain in cache; lazy expiration upon next get() of an item
Example
`javascript
const cache = fifo();
cache.ttl = 3e4;
``