Fun cache
This is the fun and cache.
How does it work:
It stores a map of results of a function and uses arguments as keys, for faster response,
Note that if the function result in different results with the same argument, the cache wouldn't work.
How to use:
import funcache from "func-cache";
const cachedFibonacci = funcache((num: number) => {
}, options);
console.log(cachedFibonacci(1000));
console.log(cachedFibonacci.noCache(1000));
console.log(cachedFibonacci.clearCache());
Options:
import funcache, { localStorageCacher, fSCacher, redisCacher, upstashCacher } from "func-cache";
const options = {
lifeTime: 1000,
debounceTimer: 200,
async: true,
...localStorageCacher("_cachePlace_for_fibonacci"),
...fSCacher("./_cachePlace_for_fibonacci.json"),
...redisCacher("_cachePlace_for_fibonacci", {
client: redisClient,
}),
...upstashCacher("_cachePlace_for_fibonacci", {
client: upstashClient,
}),
};