https://github.com/isaachinman/fs-memoize
A simple, zero-dependency NodeJs filesystem memoizer.
https://github.com/isaachinman/fs-memoize
cache memoization memoize nodejs
Last synced: about 2 months ago
JSON representation
A simple, zero-dependency NodeJs filesystem memoizer.
- Host: GitHub
- URL: https://github.com/isaachinman/fs-memoize
- Owner: isaachinman
- Created: 2021-06-17T19:25:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-20T12:30:56.000Z (almost 5 years ago)
- Last Synced: 2025-01-14T17:20:05.603Z (over 1 year ago)
- Topics: cache, memoization, memoize, nodejs
- Language: TypeScript
- Homepage:
- Size: 69.3 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fs-memoize
[](https://badge.fury.io/js/fs-memoize)
[](https://circleci.com/gh/isaachinman/fs-memoize)
**A simple, zero-dependency NodeJs filesystem memoizer.**
### Installation
```
yarn install fs-memoize
```
### Usage
```tsx
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.