🔥🛢 ExtremeCache
Extremely performant cache for production usage (1.2 million ops/s). Completely synchronous, no Promises required.
Built with:
- LokiJS High-performance Datastore package
- Native NodeJs Crypto package
Installation
npm install extreme-cache
Usage
Add this to the js file that you are using it in:
const ExtremeCache =
Simple usage:
const ExtremeCache = const cache = 'my-custom-cache' cache // No expirycache // Expires after 60000 milliseconds, which is 60 seconds let cat = cachelet dog = cache console // outputs the value - 'garfield'console // outputs the value - 'odi'
Another example usage:
const ExtremeCache = const cache = 'my-custom-cache' // ---- Insert a value with an expiry of 5.0 seconds ----cache // ---- Insert a value with no expiry ----cache
Accessible globally, meaning that no matter what file you are using it in your NodeJS project, as long as the cache name is the same, it will be referring to the same cache:
Inside File_A.js
:
// File_A.js const ExtremeCache = const cache = 'my-unique-cache-name' cache
Inside File_B.js
:
// File_B.js const ExtremeCache = const cache = 'my-unique-cache-name' let value = cache console // outputs 'garfield'
API Reference
-
set(key, value, expiryInMs)
Usage:
const ExtremeCache =const cache = 'my-custom-cache'// Set with an expirycache// Set without an expirycache -
get(key)
Usage:
const ExtremeCache =const cache = 'my-custom-cache'cachelet value = cacheconsole // outputs the value - 'garfield' -
delete(key)
Usage:
const ExtremeCache =const cache = 'my-custom-cache'cachelet value = cacheconsole // outputs the deleted object - { key: 'cat-name', value: 'garfield', timeoutInMs: undefined } -
dump()
Usage:
const ExtremeCache =const cache = 'my-custom-cache'cachecachelet value = cacheconsole // outputs the entire cache in an array - [{ key: 'cat-name', value: 'garfield', timeoutInMs: undefined }, { key: 'dog-name', value: 'odi', timeoutInMs: 5000 }] -
clearAll()
Usage:
const ExtremeCache =const cache = 'my-custom-cache'cachecachelet value = cacheconsole // outputs the entire cache in an array - [{ key: 'cat-name', value: 'garfield', timeoutInMs: undefined }, { key: 'dog-name', value: 'odi', timeoutInMs: 5000 }]let cacheName = cache // Clears the cache and returns the cache name as a string - 'my-custom-cache'value = cacheconsole // outputs the entire cache in an array, which will be empty by now - []
Tests
npm test
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.