Registry / storage / react-native-cachemere

react-native-cachemere

JSON →
library1.2.0jsnpmunverified

An async cache manager for React Native, version 1.2.0. It wraps @react-native-community/async-storage to provide a simple API for caching serializable data with TTL and attempt-based invalidation. The library offers predefined TTL constants (e.g., TTL_12H) and methods like get, set, getAll, clear, clearExpired, and clearByRegex. It is lightweight and focused on React Native, unlike general-purpose cache libraries such as node-cache or lru-cache which are not async or storage-backed. Last updated in 2019; maintenance status is unclear.

npm install react-native-cachemere
INSTALL
IMPORT
SIG · REACT-NATIVE-CACHE
R
react-native-cachemere
storagejavascriptv1.2.0
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-cachemere'
✗ import { Cache } from 'react-native-cachemere'
The package uses default export, not named export.
default (using require)
✓ const Cache = require('react-native-cachemere').default
✗ const Cache = require('react-native-cachemere')
When using CommonJS require, you must access .default because the module uses ESM default export.
TTL constants
✓ Cache.TTL_12H
✗ import { TTL_12H } from 'react-native-cachemere'
TTL constants are properties of the default exported Cache object, not named exports.

Shows basic usage: get cached data, fetch if missing, then cache with TTL and attempt count.

import Cache from 'react-native-cachemere'; import AsyncStorage from '@react-native-community/async-storage'; // Initialize (optional if AsyncStorage is already set up) const getData = async () => { const CACHE_KEY = 'my_key'; const cached = await Cache.get(CACHE_KEY); if (cached) return cached; const data = await fetch('https://api.example.com/data').then(res => res.json()); await Cache.set(CACHE_KEY, data, Cache.TTL_12H, 3); return data; }; getData().then(console.log);
Debug
Known issues
breakingAsyncStorage has been removed from React Native core since version 0.60. You must install @react-native-community/async-storage separately.
fix
Install @react-native-community/async-storage and link it according to your React Native version.
affects: >=1.0.0
deprecatedPackage has not been updated since 2019; may have compatibility issues with newer React Native versions.
fix
Consider migrating to a maintained alternative like react-native-mmkv or async-storage wrappers.
affects: >=1.0.0
gotchaThe `data` passed to `set` must be serializable to JSON; objects with functions or circular references will cause errors.
fix
Ensure data is JSON-serializable. Use JSON.stringify/parse if needed.
affects: >=1.0.0
gotchaWhen using `get`, expired cache entries are automatically cleared but the returned value is `null`. Do not confuse with `undefined`.
fix
Always check for `null` and handle accordingly.
affects: >=1.0.0
gotchaThe `clearByRegex` method deletes all keys matching the regex unconditionally; there is no confirmation.
fix
Use a specific regex to avoid unintended data loss.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module '@react-native-community/async-storage'
Missing peer dependency.
fix
npm install @react-native-community/async-storage
Cache.get is not a function
Using named import instead of default import.
fix
import Cache from 'react-native-cachemere' (without curly braces)
TypeError: Invalid attempt to spread non-iterable instance
Data passed to `set` is not an array or object but an iterable?
fix
Ensure data is a plain serializable object.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
@react-native-community/async-storagerequiredRequired peer dependency as AsyncStorage was removed from React Native core.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
react-native-cachemere — npm install react-native-cachemere · libregistry