Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
memo-cache
Advanced tools
A memoization and caching library for NodeJS.
$ npm install memo-cache
let memoCache = require('memo-cache');
cacheName
String - name of the cacheoptions
Object - options for the cache, specifying any of the following:cloneValues
Boolean - should returned values be clones of the original? [Default: false]maxSize
Integer - maximum number of keys to store in this cache; if null, then unlimited [Default: null]Return Value: An object with the following functions to modify the created cache. Please note that these functions do not require the cacheName.
let myCache = memoCache.cache.create('myCache');
console.log(myCache);
// Output:
// { set: [Function], -- function(key, value)
// get: [Function], -- function(key)
// getAll: [Function] -- function ()
// exists: [Function], -- function(key)
// clear: [Function], -- function()
// size: [Function], -- function()
// options: [Function] } -- function()
cacheName
String - name of the cachekey
String - key to be used to store the valuevalue
Any - value to be stored in the cacheReturn Value: If the item is stored, then the stored value is returned, otherwise null
is returned.
memoCache.cache.set('myCache', 'isExample', true);
// OR (if using the myCache variable from above):
myCache.set('isExample', true);
cacheName
String - name of the cachekey
String - key to be used to retrieve the valueReturn Value: If there is an item stored at the given key, then the stored value is returned, otherwise null
is returned.
memoCache.cache.get('myCache', 'isExample'); // => true
memoCache.cache.get('myCache', 'isNotExample'); // => null
// OR (if using the myCache variable from above):
myCache.get('isExample'); // => true
myCache.get('isNotExample'); // => null
cacheName
String - name of the cacheReturn Value: If there are items stored in the cache, they will be returned as a JS document.
memoCache.cache.getAll('myCache'); // => {}
memoCache.cache.get('notAValidCache'); // => null
// OR (if using the myCache variable from above):
myCache.getAll('isExample'); // => {}
myCache.getAll('notAValidCache'); // => null
cacheName
String - name of the cachekey
String - key to be deletedReturn Value: If there is an item stored at the given key, then the stored value is returned, otherwise null
is returned.
memoCache.cache.remove('myCache', 'isExample'); // => true
memoCache.cache.remove('myCache', 'isNotExample'); // => null
// OR (if using the myCache variable from above):
myCache.remove('isExample'); // => true
myCache.remove('isNotExample'); // => null
cacheName
String - name of the cachekey
String - key to be checkedReturn Value: If there is an item stored at the given key, then true
is returned, otherwise false
is returned.
memoCache.cache.exists('myCache', 'isExample'); // => true
memoCache.cache.exists('myCache', 'isNotExample'); // => false
// OR (if using the myCache variable from above):
myCache.exists('isExample'); // => true
myCache.exists('isNotExample'); // => false
cacheName
String - name of the cacheReturn Value: If the cache is cleared, then true
is returned, otherwise false
is returned.
memoCache.cache.clear('myCache'); // => true
// OR (if using the myCache variable from above):
myCache.clear(); // => true
cacheName
String - (optional) name of the cache; If not specified, the size of all caches is returnedReturn Value: The size of the cache(s).
memoCache.cache.size('myCache'); // => 1
memoCache.cache.size(); // => 1
// OR (if using the myCache variable from above):
myCache.size(); // => 1
cacheName
String - name of the cacheReturn Value: If the cache exists, then the options object is returned, otherwise null
is returned.
memoCache.cache.options('myCache'); // => { cloneValues: boolean, maxSize: Number, memoHashFunction: Function }
// OR (if using the myCache variable from above):
myCache.options(); // => { cloneValues: boolean, maxSize: Number, memoHashFunction: Function }
cacheName
String - name of the cacheoptions
Object - options for the cache, specifying any of the following:cloneValues
Boolean - should returned values be clones of the original? [Default: false]maxSize
Integer - maximum number of keys to store in this cache; if null, then unlimited [Default: null]memoHashFunction
Function - used to map the input arguments to a String. The result of this function becomes the key for the function result valuelet memoCache = require('memo-cache');
let myFunction = function (aString) { console.log('cache miss!'); return aString; };
let myFunctionMemoized = memoCache.memoize(myFunction, {maxSize: 10});
myFunctionMemoized('testing'); // => 'testing' (Prints 'cache miss!' to the console)
myFunctionMemoized('testing'); // => 'testing' (Does not print 'cache miss!')
$ npm test
Note: This requires mocha
, should
, async
, and underscore
.
FAQs
A memoization and caching library for NodeJS
The npm package memo-cache receives a total of 0 weekly downloads. As such, memo-cache popularity was classified as not popular.
We found that memo-cache demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.