https://github.com/martinheidegger/async-cache
Simple, fast, no-dependency cache for async calls.
https://github.com/martinheidegger/async-cache
Last synced: 3 months ago
JSON representation
Simple, fast, no-dependency cache for async calls.
- Host: GitHub
- URL: https://github.com/martinheidegger/async-cache
- Owner: martinheidegger
- License: mit
- Created: 2024-02-27T02:00:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-29T07:46:33.000Z (over 1 year ago)
- Last Synced: 2025-02-05T00:42:00.510Z (5 months ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
Simple, fast, no-dependency cache for async calls.
```js
import { createCache } from '@leichtgewicht/async-cache'
const cache = createCache({
resolver: async (key) => {
// load data or do something else to get the value for the key
return value
},
maxSize: 1000, // max amount of keys cached at the same time
maxAgeMs: 1000 // (optional) maxAge for a result before refetching
})const result = await cache.get('key') // load the key, if present in cache and not expired, will return previous value
result // result as provided by the async resolver
```Note: Based on, but not depending on, [HashLRU](https://github.com/dominictarr/hashlru/)