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 fSCacher from "func-cache/tools/fs";
import redisCacher from "func-cache/tools/redis";
import upstashCacher from "func-cache/tools/upstash";
import funcache, { localStorageCacher } 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,
}),
};