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

0.0.5 • Public • Published

npm version CircleCI

Cache Facade

Browser Cache inspired by Laravel's cache::remember. You can reduce API call with fluent syntax.

Installation

yarn add cache-facade

Usage

import cache from 'cache-facade'
 
async someAsyncFunction() {
  const countries = await cache.remember('countries', 30, () => {
    return countryApi.get()
  })
  console.log(countries)
}

In the above example, cache.remember will look for saved cache first. Then, if cache found then return it. Else the third function's result will be passed. If over 30 minutes passed since the cache saved, Cache Facade will run the third function and save it.

Syntax

cache.remember

cache.remember(keyNamestring, expiredTimeInMinutesnumber, otherwise: () => Promise<any>)

cache.setDriver

Set storage driver. Default is localStorage.

import cache, { Driver } from 'cache-facade'
 
cache.setDriver(Driver.memory)
cache.setDriver(Driver.localStorage)

TODO

  • React Native support. Add AsyncStorage Driver.
  • Custom driver support.

/cache-facade/

    Package Sidebar

    Install

    npm i cache-facade

    Weekly Downloads

    1

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    267 kB

    Total Files

    27

    Last publish

    Collaborators

    • acro5piano