Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
memoize-cache
Advanced tools
A configurable cache support for functions (https://www.npmjs.com/package/async-deco). It contains:
Extend this object to implement the cache with different storage/databases. The extension should include at least "_set" and "_get" Use cache-ram source as reference implementation.
The constructor takes an option object with 3 optional attributes:
Example:
var Cache = require('memoize-cache/cache-ram'); // or require('memoize-cache').CacheRAM;
// no values, uses always the same key for store any value
var cache = new Cache();
// using the id property of the first argument
// this cache will store maximum 100 items
// every item will be considered stale and purged after 20 seconds.
var cache = new Cache({ getKey: function (config){
return config.id;
} }, maxLen: 100, maxAge: 20000);
cache.push(args, output);
This function signature is designed to simplify caching of a function call. So it takes the arguments used for the call and the output. "args" is an array containing the arguments passed to the function that generated the output. This function is a "fire and forget" caching request. So there is no need of waiting for an answer, but if you want you can use a callback as third argument. It returns an object or undefined if the value won't be cached (because the TTL is 0 for example, or the resulting cachekey is null). This object contains:
This function caches a value. It is as back door to push data in the cache.
cache.set(keys, maxValidity, maxAge, data, next);
cache.query(args, function (err, result){
// result.cached is true when you find a cached value
// result.hit is the value cached
// result.timing is the time spent in ms to retrieve the value (also used for cache miss)
// cached.key is the key used to store the value (might be useful for debugging)
// cache.stale (true/false) depending on the maxValidity function (if defined)
});
"args" is an array containing the arguments passed to the function that generated the output.
var key = cache.getCacheKey(...);
It takes as arguments the same arguments of the function. It returns the cache key. It uses the function passed in the factory function.
The cache object is in the "cache" property and it support the API specified here: https://github.com/sithmel/little-ds-toolkit#lru-cache
There are 3 methods available:
cache.purgeAll(); // it removes the whole cache (you can pass an optional callback)
cache.purgeByKeys(keys);
// it removes the cache item with a specific key (string) or keys (array of strings).
// You can pass an optional callback.
cache.purgeByTags(tags);
// it removes the cache item marked with a tag (string) or tags (array of strings).
// You can pass an optional callback.
FAQs
A cache support for memoized functions
The npm package memoize-cache receives a total of 7 weekly downloads. As such, memoize-cache popularity was classified as not popular.
We found that memoize-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.