Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Simple Node.js based Redis cache for storing large collections of data.
Install with npm: npm install rediscache
Simple Node.js based Redis cache for storing large collections of data.
RedisCache makes it very simple to asynchronously respond with a collection of models from the cache. It uses method chaining for clarity in conjunction with the promise pattern.
It's a prerequisite to have Redis installed. Once installed you can begin the Redis server with redis-server
.
Initiate the Node.js server with node example/server.js
and then point your browser to localhost:3000
.
Using Node.js you need to first include RedisCache to begin using it.
var cache = require('rediscache');
RedisCache will establish a connection with the Redis server once you've invoked connect
– passing in the port
, host
, and password
– all of which being optional.
By default RedisCache will attempt to connect to 127.0.0.1
on port 6379
with no auth password.
cache.connect(6379).configure({
expiry: 86400
});
With the above code example we're also invoking configure
which allows us to specify additional options such as expiry
(default is 86400
).
RedisCache should now have connected with Redis, and you're ready to begin adding Redis caching to your actions.
Like promises – which RedisCache uses, you need to setup a method chain for each step. RedisCache uses: fetch('cache-name')
-> otherwise(function(deferred, cacheKey) {})
-> then(function(models) {})
-> fail(function() {})
.
cache.fetch('words').otherwise(function(deferred, cacheKey) {
// Read the file because we don't have a cache object currently.
fs.readFile('words.json', 'utf8', function(error, models) {
// Store the data in the Redis cache object.
deferred.resolve(JSON.parse(models));
});
}).then(function(models) {
// We have the data so we can output it to the browser!
response.send(models);
}).fail(function() {
// Invoked when you reject the promise above.
response.send([]);
});
In the above code we first attempt to load the cache with fetch
, and if that doesn't exist then the otherwise
method will be invoked – it's up to you to resolve
or reject
the promise. If it succeeds then it will go into then
to output using response.send
, else it will fall into fail
and output an empty array ([]
).
The above example may seem quite verbose for one line, however it's merely invoking a sequence of methods as is typical with promises. To make it more compact you could place each method into your object.
var responder = {};
cache
.fetch('words')
.otherwise(responder.loadCollection)
.then(responder.sendResponse)
.fail(responder.sendEmptyResponse);
That way you could abstract the responder
and use that object for each one of your collection calls – otherwise
sends the cache key as the second argument for abstraction purposes.
FAQs
Simple Node.js based Redis cache for storing large collections of data.
The npm package rediscache receives a total of 260 weekly downloads. As such, rediscache popularity was classified as not popular.
We found that rediscache 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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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.