An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

💾 react-native-modest-cache



Simple cache wrapper for AsyncStorage





Package version


Downloads


Standard


Travis Build


Standard Readme


License


PRs


Greenkeeper

Table of Contents

Table of Contents

  • About

  • Install

  • Usage

  • Contribute

  • License
  • ## 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.