small-cache
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Small Cache

🎈 The simplest, easiest, and most minimalist way 😃 to cache your requests on your frontend (JS/TS, with React.js, Vue.js, Angular, and all others)

It's as easy as this:

      const creatorsListData = await getFromCache(
        'creators', // cache key
        async () => await creatorsService.get() // the fetch data function
      )

Or as simple as:

      const product = await getFromCache<Product>(
        'product-123', // cache key
        async () => { // the fetch data function
            const { data } = await axios.get<Product>('https://example.com/products/123')
            return data;
        }
      )

You can also control the cache TTL (Time to Live) or disable caching using a third parameter, the options:

      const creatorsListData = await getFromCache(
        'creators', // cache key
        async () => await creatorsService.get() // the fetch data function,
        { // options parameter
            TTL_InSeconds: 60, // cache TTL (time to expire in seconds)
            enabled: true // enable or disable the caching
        }
      )

And yes, that's all! Life can be simple sometimes ✨

Package Sidebar

Install

npm i small-cache

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.74 kB

Total Files

5

Last publish

Collaborators

  • wilsonneto