Skip to content

A simple in-memory cache, for nodejs and the browser, with time based expiration policies

Notifications You must be signed in to change notification settings

ehmpathy/simple-in-memory-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-in-memory-cache

test publish

A simple in-memory cache, for nodejs and the browser, with time based expiration policies.

Install

npm install --save simple-in-memory-cache

Example

Quickly set and get from the cache:

import { createCache } from 'simple-in-memory-cache';

const { set, get } = createCache();
set('meaning of life', 42);
const meaningOfLife = get('meaning of life'); // returns 42

Items in the cache live 5 minutes until expiration, by default.

You can change this default when creating the cache:

const { set, get } = createCache({ defaultSecondsUntilExpiration: 10 * 60 }); // updates the default seconds until expiration to 10 minutes

And you can also override this when setting an item:

set('acceleration due to gravity', 9.81, { secondsUntilExpiration: Infinity }); // gravity will not change, so we dont need to expire it

About

A simple in-memory cache, for nodejs and the browser, with time based expiration policies

Resources

Stars

Watchers

Forks

Packages

No packages published