cache-easy
v1.0.3
Published
[![NPM Version][npm-version-image]][npm-url] [![NPM Install Size][npm-install-size-image]][npm-install-size-url] ![Coverage][coverage-image] [![Github Issues][github-issues-image]][github-issues] ![Dependecies][dependencies-image]
Downloads
41
Maintainers
Readme
Simple Cache
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
If this is a brand new project, make sure to create a package.json
first with
the npm init
command.
Installation is done using the
npm install
command:
$ npm install cache-easy
Examples
import CacheEasy from 'cache-easy';
const defaultTtl = 10000; // 10 sec
const cache = new CacheEasy(ttl);
cache.set('key', 'Hello World'); // ttl is 10 sec
cache.set('otherKey', 'Hello World', 1000); // ttl is 1 sec
cache.has('key'); // => true
cache.get('key'); // => Hello World
cache.delete('key');
cache.has('key'); // => false
const value = async () => {
// do async job
return 'Hello from Promise';
};
// it's don't call value if key is already set and ttl is valid
const key = await cache.getOrSet('key', value); // value can take promise, function or classic value
console.log(key); // => 'Hello from Promise'