wakanda-storage
provides an easy to use Node storage, shared between all your Node processes (as for Node cluster mode).
Be aware, wakanda-storage
is shared between all Node processes. The storage memory is not freed until destroy()
is called.
npm install wakanda-storage
let Storage = require('wakanda-storage');
let movies = Storage.create('movieStorage');
// let movies = Storage.get('movieStorage');
let movieArr = ["Batman", "Superman"];
movies.set('MyMovieCollection', movieArr);
movies.get('MyMovieCollection');
// ["Batman", "Superman"]
Storage.destroy('movieStorage');
Create a storage. By default, the storage size is defined to 1048576 octets.
let movies = Storage.create('movieStorage');
Get an existing storage
let movies = Storage.get('movieStorage');
Destroy an existing storage
As wakanda-storage
is shared between all Node processes, the storage memory is not freed until destroy()
is called.
Storage.destroy('movieStorage');
Set a storage key/value.
Date
and Buffer
are not supported.
movies.set('total', 30);
Get a storage key/value
let totalMovies = movies.get('total');
Remove a storage key
movies.remove('total');
Removes all keys/values from the storage
movies.clear();
Lock storage. Storage cannot be update except by the thread who lock it. If already lock, then it waits until the storage is unlock.
movies.lock();
Unlock storage
movies.unlock();
Try to lock the storage. If already lock, then it returns false
.
movies.tryLock();