Just Cache
Simple in-memory cache manager and controller for Node JS with TTL and storage size limit.
const Just = ; const cache = ; cache;cache;cache; cache; // { foo: "bar" };
Installation
Installation is easy with the npm command
$ npm install just-cache --save
Features
- Cache manager with basic and simples commands.
- Storage size info.
- High test coverage.
- Automatic storage limit management.
- Compatible with Typescript.
Usage
put (key, value, ttl)
Set or update cache value.
set (key, value, ttl)
Add a new cache. If the cache key already exists, will not set the value.
get (key)
Return the value stored.
size ()
Return the stored cache size. (value in bytes).
sizeText ()
Return the stored formated size string.
clean ()
Clean all stored cache.
has (key)
Check if contains stored key cache.
delete (key)
Remove existing cache by key.
keys ()
Get all stored keys.
count ()
Count all stored keys.
Examples
Set TTL on storage cache
const cache = ttl: 10 // seconds; cache;cache;cache; // 'with me' // ... after 10 seconds:cache; // nullcache; // falsecache; // 1 cache; // 'with me'
Set memory storage bytes limit. If new values exceed the memory limit, the first key in the queue will be removed during the sending of the new value.
const cache = limit: 100 // in bytes;
Check cache size:
cache;cachesize; // 8cache; // '8 bytes'
Options
- ttl - General ttl value. Case use set or put with TTL this option will be ignored.
- limit - Storage size limit in bytes.
TODO
- Actions callbacks.
- Info logger option.