https://github.com/tiaanduplessis/react-native-modest-cache
💾 Simple cache for AsyncStorage
https://github.com/tiaanduplessis/react-native-modest-cache
async-storage cache react-native storage
Last synced: 10 months ago
JSON representation
💾 Simple cache for AsyncStorage
- Host: GitHub
- URL: https://github.com/tiaanduplessis/react-native-modest-cache
- Owner: tiaanduplessis
- License: mit
- Created: 2017-04-14T22:35:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-11-17T09:00:11.000Z (over 6 years ago)
- Last Synced: 2024-08-09T01:38:35.902Z (almost 2 years ago)
- Topics: async-storage, cache, react-native, storage
- Language: JavaScript
- Size: 152 KB
- Stars: 23
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
💾 react-native-modest-cache
Simple cache wrapper for AsyncStorage
Table of Contents
Table of Contents
## About
This module is a wrapper around [react-native-modest-storage](https://github.com/tiaanduplessis/react-native-modest-storage) that extends it for handling cached values.
## Install
```sh
$ npm install --save react-native-modest-cache
# OR
$ yarn add react-native-modest-cache
```
## Usage
```js
import cache from 'react-native-modest-cache'
cache.set('foo', 5, -5) // (key, value, expiryDateInMinutes)
cache.set('bar', 90) // Default to 60 min
cache.set('baz', {hello: 'Friend'})
cache.isExpired('foo').then(console.log) // true
cache.isExpired('bar').then(console.log) // false
cache.get('foo').then(console.log) // undefined
cache.get('bar').then(console.log) // 90
cache.get('baz').then(console.log) // Object {hello: "Friend"}
cache.remove('bar')
cache.get('bar').then(console.log) // undefined
cache.set('bar', 50, {
interval: 'year', // 'year', 'quarter', 'month', 'week', 'day', 'minute' or 'second'
units: 2
})
cache.isExpired('bar').then(console.log) // false
cache.get('bar').then(console.log) // 50
cache.flushExpired()
cache.flush().then(() => {
cache.get('bar').then(console.log) // undefined
})
```
## Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
## License
Licensed under the MIT License.