A RelayCacheManager implementation for local data caching on React Native apps. Based on relay-cache-manager.
Relay defines the CacheManager
interface which lets you write and read records to a local cache.
Relay will check the cache first when identifying what data it has/needs; by implementing a CacheManager
you can render locally cached data quickly while Relay queries your API and updates the data when the response comes in.
$ npm install --save rn-relay-cache-manager
Just create a instance of CacheManager and inject it to the Relay Store:
import CacheManager from 'rn-relay-cache-manager';
const cacheKey = '__cache_key__';
const cachedData = await AsyncStorage.getItem(cacheKey);
const cacheManager = new CacheManager({
cacheKey, // optional
cachedData, // optional
storage: AsyncStorage, // default
});
Relay.Store.injectCacheManager(cacheManager);
cacheKey
: (optional) A string with the key used by storage to read/write data. Default value:__RelayCache__
.cachedData
: (optional) The loaded cache objectstorage
: The key-value persistent system that the cache manage will use. Default value:AsyncStorage
fromreact-native
.
- Add an example
- Write tests