Skip to content

tiaanduplessis/react-native-modest-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💾 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

    $ 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.