Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

simple-in-memory-cache

ehmpathy1.7kMIT0.4.0TypeScript support: included

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

cache, memory, in-memory, browser, browser cache, nodejs, nodejs cache, simple, simple cache, time to live, ttl, expiration

readme

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

changelog

Changelog

0.4.0 (2024-12-26)

Features

  • terms: use uni-time glossary for duration term (#9) (b80e053)

0.3.3 (2024-09-01)

Bug Fixes

  • cicd: remove test commmits while best practs upgrade paused (f2826fa)
  • practs: bump practs to latest best (#7) (33e3784)

0.3.2 (2024-09-01)

Bug Fixes

  • expire: expiration of 0 seconds should be immediate (3940775)

0.3.1 (2023-07-28)

Bug Fixes

  • inputs: add seconds as alias to defaultSecondsUntilExpiration (4ad0a09)
  • practs: use latest best practices (0937888)

0.3.0 (2022-11-24)

Features

  • keys: enable accurate retrieval of all valid cache keys (5a70816)

0.2.1 (2022-11-23)

Bug Fixes

  • cicd: add test:format script to unblock ghactions (f4f645c)

0.2.0 (2022-11-23)

Features

  • cicd: add please release github cicd (43f27ea)

Bug Fixes

  • remote: replace references from uladkasach repo to ehmpathy repo (983e8ac)
  • types: expose a type for an instance of the cache (1bcbf9b)