@lindeneg/memory-cache
TypeScript icon, indicating that this package has built-in type declarations

1.1.10 • Public • Published

@lindeneg/memory-cache

typescript bundle-size license

Sandbox


React hook for caching data in-memory. If you'd like to make the cache persistent, take a look at @lindeneg/browser-cache.

Installation

yarn add @lindeneg/memory-cache

Usage

import useMemoryCache from '@lindeneg/memory-cache';

function SomeComponent() {
  const { cache } = useMemoryCache<{ id: number }>();

  // set item
  cache.set('id', 1);

  // get item
  cache.get('id');

  // listen to event
  cache.on('trim', (removed) => {
    console.log('trim removed these keys from cache: ', removed);
  });

  // and so on
}

The documentation here can be used.

Dependents (1)

Package Sidebar

Install

npm i @lindeneg/memory-cache

Weekly Downloads

2

Version

1.1.10

License

MIT

Unpacked Size

7.38 kB

Total Files

6

Last publish

Collaborators

  • christianlindeneg