react-native-modest-cache

1.0.3 • Public • Published

Table of Contents

Simple cache wrapper for AsyncStorage



Built with ❤︎ by Tiaan and contributors

Table of Contents

Table of Contents
  • About
  • Install
  • Usage
  • Contribute
  • License
  • About

    This module is a wrapper around react-native-modest-storage that extends it for handling cached values.

    Install

    $ npm install --save react-native-modest-cache
    # OR 
    $ yarn add react-native-modest-cache

    Usage

    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.

    Package Sidebar

    Install

    npm i react-native-modest-cache

    Weekly Downloads

    20

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    9.8 kB

    Total Files

    8

    Last publish

    Collaborators

    • tiaanduplessis