Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
cacheman-promise
Advanced tools
Cacheman library with a promise interface.
$ npm install --save cacheman-promise
Cacheman-promise only support set
, get
, del
, clear
, pull
and wrap
promise interface.
Please refer to Cacheman Options API
var Cacheman = require('cacheman-promise');
var options = {
ttl: 90,
engine: 'redis',
port: 9999,
host: '127.0.0.1'
};
var cache = new Cacheman('todo', options);
// or
var cache = new Cacheman(options);
Usage:
var key = 'foo';
var data = 'bar';
cache.set(key, {name: data})
.then(function(val){
// output "{name: 'bar'}"
console.log(val);
});
You can pass array
or string
as key.
Usage:
cache.set('foo', 'bar');
cache.get('foo')
.then(function(val){
// output "bar"
console.log(val);
});
pass array
as multiple keys
Usage:
cache.set('foo', 1);
cache.set('bar', 2);
cache.get(['foo', 'bar'])
.then(function(result){
// output {"foo": 1, "bar": 2}
console.log(result);
});
If you need to retrieve an item from the cache and then delete it, you may use the pull
method. Like the get
method, null
will be returned if the item does not exist in the cache.
cache.set('foo', 'bar');
cache.pull('foo')
.then(function(result){
// output 'bar'
console.log(result);
}).then(function() {
return cache.get('foo');
}).then(function(result) {
// output 'null'
console.log(result);
});
You can pass default value as second paramaeter if the item doesn't exist in the cache.
// make sure `foo` cache doesn't exist.
cache.del('foo');
cache.pull('foo', 'bar')
.then(function(result){
// output 'bar'
console.log(result);
});
You can pass array
or string
as key.
Usage:
cache.del('foo')
.then(function(){
console.log('foo was deleted');
});
or
cache.del(['foo', 'bar'])
.then(function(){
console.log('foo and bar was deleted');
});
Clear some items with prefix name
:
cache.clear('foo*')
.then(function(){
console.log('clear cache with `foo` prefix name like `foo1`, `foo2` etc.');
});
Clear all cache as follwoing:
cache.clear()
.then(function(){
console.log('cache is now clear');
});
Wraps a function in cache. I.e., the first time the function is run, its results are stored in cache so subsequent calls retrieve from cache instead of calling the function.
var key = 'foo';
var data = 'bar';
cache.wrap(key, data)
.then(function(val) {
// get foo key from cache
return cache.get(key);
}).then(function(val) {
// output 'bar'
console.log(val);
});
$ npm test
FAQs
cacheman with a promise interface.
We found that cacheman-promise 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.