Cached call
Cache the function result by wrapping it
Installation
npm i cached-call
Basic Usage
const CachedCall = const cache = v
Options
const cache = ...args
name | description | default | example |
---|---|---|---|
name |
Function name for cache key | (required) | |
func |
Cache target function | (required) | |
key |
Key for create cache key (function or value) | (...args) => args |
1 , 'moo' |
maxAge |
Maximum age in ms | (required) | 300 , 100 |
args |
Arguments that will be passed to key function |
(required) | |
max |
The maximum size of the cache | Infinity |
1000 , 100 |
stale |
return the stale value before deleting it | false |
true |
cacheError |
Cache error and rejection for ms | undefined |
1000 |
Auto generated internal cache key by default
JSON
Examples
Custom key function
Use only 3rd, 4th arguments for key
const key = n1 n2const pickArgs = // cache key : ["someFunction", 1 ,2]
Clear cache at 10 or 20 minutes for every hour
const dayjs = const everyHour = - Dateconst every10minutes = const every20minutes =
Retry after 1s when error
const retryThrottle =
License
The MIT License (MIT)
Copyright (c) 2020 Elevista