Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
func-cache
Advanced tools
This is the fun and cache.
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.
import funcache from "func-cache";
const cachedFibonacci = funcache((num: number) => {
// ... your function here
}, options); // about the options, see below
console.log(cachedFibonacci(1000)); //-- viewing the result
console.log(cachedFibonacci.noCache(1000)); //-- run without caching
console.log(cachedFibonacci.clearCache()); //-- to clear the cache
import fSCacher from "func-cache/tools/fs"; // only for server
import redisCacher from "func-cache/tools/redis"; // only for server
import upstashCacher from "func-cache/tools/upstash"; // only for server
import funcache, { localStorageCacher } from "func-cache";
const options = {
// (1 sec) in miliseconds
lifeTime: 1000,
/** debounce time wait to call onDataUpdate, default 1000ms */
debounceTimer: 200,
/** incase the call is async, (sometimes the script doesn't detect it's async and wont run the await for it) default: false */
async: true,
// place to store the cache, incase of restarts (browser only)
...localStorageCacher("_cachePlace_for_fibonacci"),
// place to store the cache, incase of restarts (server only). fs way
...fSCacher("./_cachePlace_for_fibonacci.json"),
// place to store the cache, incase of restarts (server only). redis way
...redisCacher(yourFunction, {
client: redisClient,
}),
// place to store the cache, incase of restarts (server only). upstash way
...upstashCacher(upstashClient, {
client: upstashClient,
}),
};
FAQs
TypeScript library for caching static functions
The npm package func-cache receives a total of 20 weekly downloads. As such, func-cache popularity was classified as not popular.
We found that func-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.