simple-stash
v1.2.1
Published
Simple local caching and lookup
Downloads
1
Readme
Simple Stash
Simple in-memory caching for Javascript.
Installation
$ npm install simple-stash --save
Usage
Get an item from memory
const cache = require('simple-stash');
const data = [
{
id: 'test-uuid-1',
name: 'John Smith'
},
{
id: 'test-uuid-2',
name: 'Jane Miller'
}
];
cache.set('users', data);
const customer = cache.get('users:id:test-uuid-1');
console.log(customer);
Logs:
{
"id": "test-uuid-1",
"name": "John Smith"
}
Get multiple items from memory
const cache = require('simple-stash');
const data = [
{
id: 'test-uuid-1',
name: 'John Smith'
},
{
id: 'test-uuid-2',
name: 'John Smith'
},
{
id: 'test-uuid-3',
name: 'Jane Miller'
}
];
cache.set('users', data);
const customers = cache.getAll('users:name:John Smith');
console.log(customers);
Logs:
[
{
"id": "test-uuid-1",
"name": "John Smith"
},
{
"id": "test-uuid-2",
"name": "John Smith"
}
]
Clear the cache
You can also remove all items from storage.
cache.clear();
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.