Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-facade

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-facade

[![npm version](https://badge.fury.io/js/onemile-router.svg)](https://badge.fury.io/js/cache-facade) [![CircleCI](https://circleci.com/gh/acro5piano/dotenv-vault.svg?style=svg)](https://circleci.com/gh/acro5piano/cache-facade)

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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(keyName: string, expiredTimeInMinutes: number, 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.

FAQs

Package last updated on 01 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc