Socket
Book a DemoInstallSign in
Socket

@uwdata/file-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uwdata/file-cache

File-based cache for JSON-serializable data.

0.0.1
latest
npmnpm
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

file-cache

File-based cache for JSON-serializable data.

Install

Requires at least Node.js v14.14.0.

npm install @uwdata/file-cache

Usage

@uwdata/file-cache is an ESM-only module - you are not able to import it with require().

Standard Usage

import { fileCache } from '@uwdata/file-cache';

// create a new cache that writes to ./.cache
// the cache directory will be created if it does not exist
const cache = fileCache();

// set cache value writes both to in-memory map and to disk
await cache.set('key', { value: true });

// get cache value reads from disk if not found in-memory
const value = await cache.get('key');
// value = { value: true}

// delete cache value from both in-memory map and disk
await cache.delete('key');

// delete cache values and folder from disk
// subsequent use of existing cache instance is ill-advised
await deleteCache();

Custom Usage

import { fileCache, deleteCache } from '@uwdata/file-cache';

// create a new cache with custom directory and time-to-live
const cache = fileCache({
  cacheDir: './.my-cache-dir', // custom cache directory
  defaultTTL: 60 * 1000, // custom time-to-live before expiration
});

// set cache value along with a custom TTL value for the entry
await cache.set('key', { value: true }, 120 * 1000);

// delete cache values and folder from disk
// subsequent use of existing cache instance is ill-advised
await deleteCache('./.my-cache-dir');

FAQs

Package last updated on 19 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.