A CacheManager implementation for local data caching in Relay
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 relay-cache-manager
Until RelayEnvironment
exposes injectCacheManager
you have to inject it directly from the RelayStoreData
instance used by your store. You can access that via the getStoreData()
method on your RelayEnvironment
instance. If you're using Relay.Store
you can just do:
import CacheManager from 'relay-cache-manager';
const cacheManager = new CacheManager();
Relay.Store.getStoreData().injectCacheManager(cacheManager);