JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q33237F
  • License LGPL-3.0

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

Package Exports

  • cache-fns
  • cache-fns/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cache-fns) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cache-fns


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

Table of Contents

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.