0.0.2 • Published 9 months ago

svelte-cached v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

🌟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

0.0.2

9 months ago