Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acro5piano/cache-facade
Frontend Cache inspired by Laravel's cache::remember
https://github.com/acro5piano/cache-facade
cache javasc laravel typescript
Last synced: 13 days ago
JSON representation
Frontend Cache inspired by Laravel's cache::remember
- Host: GitHub
- URL: https://github.com/acro5piano/cache-facade
- Owner: acro5piano
- Created: 2018-06-30T02:45:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T09:52:52.000Z (about 2 years ago)
- Last Synced: 2025-01-19T12:35:31.306Z (about 1 month ago)
- Topics: cache, javasc, laravel, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/cache-facade
- Size: 1.24 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://badge.fury.io/js/cache-facade)
[](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)
```## 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.