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.
A little in-memory cache solution for nodejs.
> npm install --save-dev nano-cache
The NanoCache constructor is also a singleton which can be used directly or as a factory.
// use the default singleton
var cache = require('nano-cache');
// or construct your own
var NanoCache = require('nano-cache');
var cache = new NanoCache();
// listen to events
cache.on('del', function (deletedKey) { /* ... */ });
cache.on('get', function (accessedKey) { /* ... */ });
cache.on('set', function (setKey) { /* ... */ });
cache.on('clear', function () { /* ... */ });
Use of the default singleton is optional. New cache objects can be constructed with custom configurations.
var NanoCache = require('nano-cache');
var cache = new NanoCache({
ttl: 30000, // max aged for cache entry
limit: 5, // max hits for a cache entry
bytes : 100 * NanoCache.SIZE.MB, // max memory use for data
});
cache.set('mykey', myvalue);
Set the item in the cache dictionary, overriding any previous value or settings for the key.
The value
must be a JSON-serializable object which includes simple strings, numbers, or booleans.
var cache = require('nano-cache');
NanoCache.set('mykey', myvalue, {
ttl: 60000, // ttl 60 seconds
limit: 10 // limits the read count to 10 times, the 10'th time will expire the cache
});
Returns the value from the cache, or null if non-existent or expired.
NanoCache.set('mykey', myvalue)
var value = NanoCache.get('mykey');
get(key)
returns a valueset(key, value, options)
sets a key/value pair, returns the value setdel(key)
deletes a key/value pair, returns the value deletedclear()
delete everythingclearExpired()
deletes all expired key with their values to free up memoryisTTLExpired(key)
check if a key's ttl is up, returns true/false
, always false
if there is no ttl setisLimitReached(key)
check if a key's read count has reached its limit, returns true/false
, always false
if there is no limit setinfo(key)
returns information about key, including access time, hits, and expirystats()
returns number of items in cache, total byte size, and hit/miss ratioEvery cache
instance extends the EventEmitter object, so it has all of its methods. However, the most common used ones are probably the following:
on(eventName, callback)
once(eventName, callback)
emit(eventName, callback)
removeListener(eventName)
removeAllListeners(eventName, listenerCallbackReference)
Every cache
instance will emit
the following events.
'del'
when a key is deleted. Its listeners callbacks will receive the deletedKey
as the 1st argument.'get'
when a key is accessed. Its listeners callbacks will receive the accessedKey
as the 1st argument.'set'
when a key is set. Its listeners callbacks will receive the setKey
as the 1st argument.'clear'
when all is clear from memory. No argument is passed to the listeners.ttl
time in msec before the item is removed from cache. defaults to null for no limit.limit
maximum number of reads before item is removed from cache. defaults to null for no limit.bytes
maximum number of bytes before an item removed from the cache. defaults to Infinity for no limit.compress
- use compression to reduce in-memory cache size. Defaults to true, but can be disabled for improved speed at the cost of memory size.minFreeMem
- items will be evicted from cache if os.freemem()
is lower. Defaults to 0% of total memory.maxEvictBytes
- maximum amount of memory to be evicted on check, which leaves time for garbage collection, defaults to 5% of total memory.Copyright (c) 2017 Cxense Inc
Authors:
MIT license https://opensource.org/licenses/MIT
FAQs
simple node cache module
The npm package nano-cache receives a total of 1,139 weekly downloads. As such, nano-cache popularity was classified as popular.
We found that nano-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
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.