fs-memoize
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

fs-memoize

npm version CircleCI

A simple, zero-dependency NodeJs filesystem memoizer.

Installation

yarn install fs-memoize

Usage

import { fsMemoize } from 'fs-memoize'

const myExpensiveFunction = async () => {
  // ...Does expensive stuff
}

const myExpensiveFunctionCached = fsMemoize(
  myExpensiveFunction,
  {
    cacheBaseName: 'myExpensiveFunction',
    ttl: 60 * 1000,
  }
)

How it works

The fsMemoize function will return back a memoized version of your async function.

A cache key is generated based on cacheBaseKey + all function arguments, stringified.

Cache life is controlled via the ttl config option, in milliseconds.

Data, by default, is stored in /tmp/fs-memoize, but the location can be changed via the optional cacheDir config option.

Readme

Keywords

none

Package Sidebar

Install

npm i fs-memoize

Weekly Downloads

3

Version

1.1.1

License

MIT

Unpacked Size

7.05 kB

Total Files

4

Last publish

Collaborators

  • isaachinman