# 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)

Latest version **0.0.5** (published 2018-07-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install cache-facade
pnpm add cache-facade
yarn add cache-facade
bun add cache-facade
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2018-07-01 |
| First published | 2018-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 260.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | gosho-kazuya |
| Maintainers | acro5piano |

## Links

- npm: https://www.npmjs.com/package/cache-facade
- Repository: https://github.com/acro5piano/storage-cache
- Homepage: https://github.com/acro5piano/storage-cache#readme
- Issues: https://github.com/acro5piano/storage-cache/issues
- npm.io page: https://npm.io/package/cache-facade

## Recent versions

- 0.0.5 (latest) — 2018-07-01
- 0.0.4 — 2018-06-30
- 0.0.3 — 2018-06-30
- 0.0.2 — 2018-06-30
- 0.0.1 — 2018-06-30

## README

[![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)

# Cache Facade

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

# Installation

```
yarn add cache-facade
```

# Usage

```ts
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

```ts
cache.remember(keyName: string, expiredTimeInMinutes: number, otherwise: () => Promise<any>)
```

## cache.setDriver

Set storage driver. Default is `localStorage`.

```ts
import cache, { Driver } from 'cache-facade'

cache.setDriver(Driver.memory)
cache.setDriver(Driver.localStorage)
```

# TODO

- [ ] React Native support. Add `AsyncStorage` Driver.
- [ ] Custom driver support.

---
_Source: https://npm.io/package/cache-facade · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
