svelte-cached
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

🌟svelte-cached

A simplified store for storing cached data. Useful for data that needs to keep in sync with it's source.

release version weekly download count primary language procentage workflow build status last commit badge licence badge


Install

npm install svelte-cached

Usage

import { cached } from 'svelte-cached';

Set the initial value for the store. To keep the store in sync with it's source, provide a retrieve async function as the second argument.

TTL is set as third argument, if not provided you will need to manually call store.retrieve() function whenever you want to sync the state.

const getLatestBitcoinPrice = async () => {
  const response = await fetch(...);
  // ...
  return price;
};

// get a fresh price every 5 seconds
const btcPrice = cached(0, getLatestBitcoinPrice, 5000);

Use the cached store instance just like any other Svelte store.

<p>Current BTC price:{$btcPrice}</p>

Licence

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i svelte-cached

Weekly Downloads

0

Version

0.0.2

License

none

Unpacked Size

4.01 kB

Total Files

4

Last publish

Collaborators

  • bartektelec