cache-easy
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Simple Cache

NPM Version NPM Install Size Coverage Github Issues Dependecies

NPM Downloads

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'

Package Sidebar

Install

npm i cache-easy

Weekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

7.22 kB

Total Files

6

Last publish

Collaborators

  • maximekreber