react-native-cache-store

1.0.2 • Public • Published

React Native Cache Store npm version

A localStorage-like wrapper around React Native's AsyncStorage with cache expiration.

100% inspired by @pamelafox's lscache. Currently being used by my project, hackerweb-ios.

WARNING: The test coverage is not very high 😅

Installation

npm i --save react-native-cache-store

API Reference

  • set(key, value, [time]) - Stores the value. Expires after specified number of minutes.

    1. key (string)
    2. value (Object | string)
    3. time (number: optional)
  • get(key) - Retrieves specified value, if not expired.

    1. key (string)
  • remove(key) - Removes a value.

    1. key (string)
  • isExpired(key) - Checks if a value has expired.

    1. key (string)
  • flush() - Removes all items.

  • flushExpired() - Removes all expired items. This method runs every time this code is initalized.

Example Usage

import CacheStore from 'react-native-cache-store';
 
CacheStore.set('key', 'value', 10); // Expires in 10 minutes
 
CacheStore.get('key').then((value) => {
  // Do something with value
});
 
CacheStore.isExpired('key')
  .then(() => {/* true */ })
  .catch(() => {/* false */})

Contribute

Of course, contributions welcomed! 🙌

License

MIT.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    95
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    95
  • 1.0.1
    1
  • 1.0.0
    1

Package Sidebar

Install

npm i react-native-cache-store

Weekly Downloads

76

Version

1.0.2

License

MIT

Last publish

Collaborators

  • cheeaun