memo-json
A memoization decorator caching JSON results to disk. Speed up development applications depending on external resources.
To install:
npm install memo-json
yarn add memo-json
Usage
import { memo } from 'memo-json'
const getDataMemo = memo(function getData(param: string) { ... })
await getDataMemo('a')
await getDataMemo('a')
await getDataMemo('b')
The first run of the above code will generate cache like below being reused in the subsequent calls.
# ${process.env.cwd()}/${functionName}-${paramHash}.json
.memo/getRemoteData-4e6c99.json
.memo/getRemoteData-dee827.json
Debug
Debug logs are available when you have DEBUG
environment.
DEBUG=memo-json ts-node your-script.ts
Options
You can own your cusomized memo()
funciton by createMemo(opts)
.
import { createMemo } from "memo-json";
const memo = createMemo({
dir: "__generated",
enable: process.env.NODE_ENV !== "production",
});
const getDataMemo = memo(function getData() { ... })
Available options:
dir
- Optional string. ".memo"
by default.enable
- Optional boolean. true
by default.
CLI
memo clean
License
Apache 2.0
Author
Soichi Takamura @piglovesyou