Skip to content

codyjdalton/simple-stash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status npm version

Simple Stash

Simple in-memory caching for Javascript.

Installation

$ npm install simple-stash --save

View on NPM

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.