Registry / storage / react-native-cache

react-native-cache

JSON →
library2.0.3jsnpmunverified

LRU cache library for React Native, built on top of AsyncStorage v2 or an included MemoryStore, with automatic pruning of least recently used items. Current stable version is 2.0.3, released in 2020, with infrequent updates. It provides a simple key-value storage with TTL support and configurable max entries. Differentiators: designed specifically for React Native, uses AsyncStorage for persistence, includes MemoryStore for in-memo caching, and supports multiple namespaces. Alternatives like react-native-community/async-storage offer lower-level access but lack LRU behavior.

npm install react-native-cache
INSTALL
IMPORT
SIG · REACT-NATIVE-CACHE
R
react-native-cache
storagejavascriptv2.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Cache
import { Cache } from 'react-native-cache'
import Cache from 'react-native-cache'
Named import since v2. Default import is incorrect.
MemoryStore
import { MemoryStore } from 'react-native-cache'
import MemoryStore from 'react-native-cache'
Named export for the in-memory store backend.

Initializes an LRU cache with AsyncStorage backend, sets and gets a value, then removes it.

import { Cache } from 'react-native-cache'; import AsyncStorage from '@react-native-community/async-storage'; const cache = new Cache({ namespace: 'myapp', policy: { maxEntries: 500, stdTTL: 0, }, backend: AsyncStorage, }); async function example() { await cache.set('key1', 'hello'); const value = await cache.get('key1'); console.log(value); // 'hello' await cache.remove('key1'); } example();
Debug
Known issues
deprecatedThe AsyncStorage dependency has been renamed to @react-native-async-storage/async-storage in later versions.
fix
Update import to '@react-native-async-storage/async-storage' or use the new package name.
affects: >=2.0.0
gotchaThe maxEntries policy must be set; otherwise, the cache has unlimited entries with potential memory issues.
fix
Always set maxEntries in the policy option.
affects: >=2.0.0
gotchastdTTL of 0 means unlimited TTL (no expiration).
fix
Set stdTTL to the desired number of seconds or omit for default (unlimited).
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: AsyncStorage is not a constructor
Importing AsyncStorage incorrectly or using wrong package name.
fix
Install @react-native-community/async-storage and import as: import AsyncStorage from '@react-native-community/async-storage'
Cannot find module 'react-native-cache'
Package not installed or wrong import path.
fix
Run 'npm install react-native-cache' and ensure import uses named import: import { Cache } from 'react-native-cache'
undefined is not an object (evaluating 'AsyncStorage.getItem')
AsyncStorage is null or undefined.
fix
Ensure AsyncStorage is correctly installed and imported, and linked for React Native < 0.60.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
@react-native-community/async-storageoptionalOptional backend for persistent storage. If not provided, in-memory store is used.
Agent activity
18 hits · last 30 days
node
18
Resources
react-native-cache — npm install react-native-cache · libregistry