Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Inspired by the php library, Stash makes it easier to save your data on multiple layers of cache
Click here to see the Facebook example running on RawGit
You can either install via npm
$ npm install stash.js
Or via bower
$ bower install stash.js
Or you can just grab a copy of the stash.js file
Syntax Updated: in order to add new drivers, I had to replace the old sync syntax, the new one is based on promises, and it now depends on bluebird
// By version 1.2 you should require('stash.js');
// It is still available on window, but is deprecated and will be removed on version 2.0
var Stash = require('stash.js');
// Initialize a stash pool
var stash = new Stash.Pool();
// Short version -- with Promise
stash.get('my/key/path').catch(function (err) {
// Data is either inexistent or expired
return slowFuncThatReturnsPromise().then(this.save);
});
// Long Version (stash.get does all of it internally)
var item = stash.getItem('my/key/path');
item.get().then(function (data) {
item.isMiss().then(function (missed) {
if (missed) {
item.lock(); // Async lock
actuallyFetchData(function (data) {
item.set(data);
callback(data);
});
} else {
callback(data);
}
});
});
You can run the node.js samples on the examples
folder to see a really basic demo
var ephemeral = new Stash.Drivers.Ephemeral();
var localStorage = new Stash.Drivers.LocalStorage('my-custom-namespace');
var indexedDB = new Stash.Drivers.IndexedDB('my-custom-dbname');
// Config info available below
var redis = new Stash.Drivers.Redis();
var memcached = new Stash.Drivers.Memcached();
var clientPool = new Stash.Pool([ephemeral, localStorage]); // It reads on this order, and writes in reverse order
var serverPool = new Stash.Pool([ephemeral, memcached, redis]);
Right now there are five drivers
serverLocations
and options
, that are passed to the node-memcached
constructor, info about configuration available hereredis.createClient()
I should create some extra drivers in a really near future... If you want to contribute with some driver, just fork e send me a pull request, will be happy to merge! =)
There are 4 cache policies right now:
Stash.Item.SP_NONE
(default): Ignores the lock
, if an item is expired, isMiss
will just return true
anywayStash.Item.SP_OLD
: will return the old value and the subsequent item.isMiss()
calls will return false
while another instance has the context lock()
edStash.Item.SP_PRECOMPUTE
: you should call item.get(Stash.Item.SP_PRECOMPUTE, time)
, where item.isMiss()
will eventually return true
for one instance time
seconds before the cache is expiredStash.Item.SP_VALUE
: a default value
should be passed along the get()
call, this value will be returned if the cache is expired and lock()
edFeel free to share any doubts, thoughts or even complaints, either on the issues, via email or send me a tweet!
FAQs
Multilayer Cache Manager for JavaScript
The npm package stash.js receives a total of 5 weekly downloads. As such, stash.js popularity was classified as not popular.
We found that stash.js 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.