Socket
Socket
Sign inDemoInstall

cache-fns

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cache-fns

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


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Install size
12.9 kB
Created
Weekly downloads
 

Readme

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.

Keywords

FAQs

Last updated on 15 Dec 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc