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

cache-fns

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-fns

Something with cache ig. Utilities for Caching / Data Fallback Handling

  • 0.0.1
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

cache-fns


Something with cache ig. Utilities for Caching / Data Fallback Handling.

Table of Contents

  • Table of Contents
  • Installation
  • Documentation
  • Contributors
  • LICENSE

Installation

Using npm:

npm install cache-fns

or if you prefer to use the yarn package manager:

yarn add cache-fns

or if you prefer to use the pnpm package manager:

pnpm add cache-fns

Documentation

useCache

useCache takes in as it's first parameter the key that will be sent to getter and setter functions to retrieve/store data.

Further arguments will be used in order to determine how the data is stored and retrieved.

In the example bellow, myLocalCache and myRemoteCache are imaginary caches that we use to demonstrate the function.

const data = await useCache<OurReturnType>(
    'myKey',
    // Resolver with both getter and setter
    {
        get: async (key) => {
            // Get the key from our local cache
            return await myLocalCache.get(key);
        },
        set: async (key, value) => {
            // Set the key in our local cache
            await myLocalCache.set(key, value);
        },
    },
    // Resolver with only getter
    async (key) => {
        // Get the key from our remote cache
        return await myRemoteCache.get(key);
    }
);

Contributors

LICENSE

This package is licensed under the GNU Lesser General Public License.

FAQs

Package last updated on 28 Jul 2022

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