Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

func-cache

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

func-cache

TypeScript library for caching static functions

  • 2.2.62
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by11.11%
Maintainers
1
Weekly downloads
 
Created
Source

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) => {
    // ... 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

Options:



import funcache, { localStorageCacher, fSCacher, redisCacher, upstashCacher } 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("_cachePlace_for_fibonacci", {
    client: redisClient,
  }),

  // place to store the cache, incase of restarts (server only). upstash way
  ...upstashCacher("_cachePlace_for_fibonacci", {
    client: upstashClient,
  }),
};

Keywords

FAQs

Package last updated on 07 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc