项目作者: tiaanduplessis

项目描述 :
💾 Simple cache for AsyncStorage
高级语言: JavaScript
项目地址: git://github.com/tiaanduplessis/react-native-modest-cache.git
创建时间: 2017-04-14T22:35:53Z
项目社区:https://github.com/tiaanduplessis/react-native-modest-cache

开源协议:MIT License

下载


💾 react-native-modest-cache


Simple cache wrapper for AsyncStorage



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

    1. $ npm install --save react-native-modest-cache
    2. # OR
    3. $ yarn add react-native-modest-cache

    Usage

    1. import cache from 'react-native-modest-cache'
    2. cache.set('foo', 5, -5) // (key, value, expiryDateInMinutes)
    3. cache.set('bar', 90) // Default to 60 min
    4. cache.set('baz', {hello: 'Friend'})
    5. cache.isExpired('foo').then(console.log) // true
    6. cache.isExpired('bar').then(console.log) // false
    7. cache.get('foo').then(console.log) // undefined
    8. cache.get('bar').then(console.log) // 90
    9. cache.get('baz').then(console.log) // Object {hello: "Friend"}
    10. cache.remove('bar')
    11. cache.get('bar').then(console.log) // undefined
    12. cache.set('bar', 50, {
    13. interval: 'year', // 'year', 'quarter', 'month', 'week', 'day', 'minute' or 'second'
    14. units: 2
    15. })
    16. cache.isExpired('bar').then(console.log) // false
    17. cache.get('bar').then(console.log) // 50
    18. cache.flushExpired()
    19. cache.flush().then(() => {
    20. cache.get('bar').then(console.log) // undefined
    21. })

    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.