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

Package detail

simple-on-disk-cache

ehmpathy36MIT1.7.0TypeScript support: included

A simple on-disk cache, supporting local and remote filesystem targets, with time based expiration policies.

cache, disk, on-disk, filesystem, s3 cache, s3, local, locally mounted, nodejs, nodejs cache, simple, simple cache, time to live, ttl, expiration

readme

simple-on-disk-cache

ci_on_commit deploy_on_tag

A simple on-disk cache, supporting local and remote filesystem targets, with time based expiration policies.

Install

npm install --save simple-on-disk-cache

Example

locally mounted

You can easily get and set to a cache persisted in a locally mounted filesystem

import { createCache } from 'simple-on-disk-cache';

const { set, get } = createCache({
  directoryToPersistTo: {
    mounted: {
      path: `${__dirname}/tmp`,
    }
  },
});
set('meaning-of-life', '42');
const meaningOfLife = get('meaning-of-life'); // returns 42

aws s3

You can also easily get and set from a cache persisted in an aws s3 fileystem

import { createCache } from 'simple-on-disk-cache';

const { set, get } = createCache({
  directoryToPersistTo: {
    s3: {
      bucket: '__bucket_name__',
      prefix: '__prefix__',
    }
  },
});
set('meaning-of-life', '42');
const meaningOfLife = get('meaning-of-life'); // returns 42

default expiration

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

per item expiration

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

1.7.0 (2024-12-26)

Features

  • util: expose cast to safe ondisk cache key procedure (74b604f)

1.6.0 (2024-12-26)

Features

  • terms: use uni-time glossary for duration term (3268ee6)

1.5.0 (2024-09-01)

Features

  • perf: prevent redundant disk.reads via memory cache for perfboost (f13539a)

1.4.0 (2024-06-26)

Features

  • config: enable async getter for directory def (5040c8b)

1.3.4 (2024-06-26)

Bug Fixes

  • cicd: enable publish post creds req (0c579b0)

1.3.3 (2024-06-26)

Bug Fixes

1.3.2 (2024-01-07)

Bug Fixes

  • dirs: mkdir when creating cache to prevent errors (b3f00fa)

1.3.1 (2022-11-25)

Bug Fixes

  • keys: decrease chance of corrupted keyfiles w/ max concurrency limit on keyfile updates (1671c8e)

1.3.0 (2022-11-25)

Features

  • resiliance: automatically recover from malformed cache files; just warn and move on (9bb3569)

1.2.1 (2022-11-24)

Bug Fixes

  • cicd: use node v16 in gh actions (e341fea)
  • deps: fix dep versions to ensure its buildable on cicd (fba09f4)
  • tests: use fs.unlink instead of fs.rm (392f410)

1.2.0 (2022-11-24)

Features

  • keys: enable accurate retrieval of active valid cache keys (3558572)

1.1.1 (2022-11-22)

Bug Fixes

  • tests: add proof that errors attempted to be set are handled correctly (ae06132)
  • types: expose a type for an instance of the cache (a21fc63)

1.1.0 (2022-10-09)

Features

  • obs: save value to cache file as observably as possible (11204fe)

1.0.1 (2022-10-09)

Bug Fixes

  • pkg: fix the package description and keywords (ddfad25)

1.0.0 (2022-10-09)

Features

  • init: publish as standalone package (cee9740)