1.2.0 • Published 8 years ago
redux-effects-fetchr-cache v1.2.0
redux-effects-fetchr
Caching middleware for redux-effects-fetchr.
Installation
npm install --save redux-effects-fetchr-cacheUsage
Installing the middleware:
import { createStore, applyMiddleware } from 'redux';
import Fetchr from 'fetchr';
import stepsMiddleware from 'redux-effects-steps';
import fetchrMiddleware from 'redux-effects-fetchr';
import fetchrCacheMiddleware from 'redux-effects-fetchr-cache';
import rootReducer from './reducers';
const fetchr = new Fetchr({
xhrPaht: '/api'
});
const cacheConfig = {
max: 500,
maxAge: 1000 * 60 * 60
};
const store = createStore(
rootReducer,
applyMiddleware(
stepsMiddleware,
fetchrCacheMiddleware(cacheConfig),
fetchrMiddleware(fetchr)
)
);redux-effects-fetchr-cache must be installed before redux-effects-fetchr.
API
Middleware
fetchrCacheMiddleware(cacheConfig, [options])
Creates redux middleware.
Arguments
cacheConfig(Object): See lru-cahce API docs for more info.options(Object):excludes(Array): An array of the resource names to not use the cache. Defaults[].fromCache(Function): Checks whether an action is target to obtain from cache. Defaults() => true.- Arguments:
action(Object): An action.state(Object): The current state of the Store.
- Returns:
- (Boolean): If
true, uses cache to obtain the resource.
- (Boolean): If
- Arguments:
toCache(Function): Checks whether an action is target to store to cache. Defaults() => true.- Arguments:
action(Object): An action.state(Object): The current state of the Store.
- Returns:
- (Boolean): If
true, saves the obtaining resource to cache.
- (Boolean): If
- Arguments:
resetCache(Function): reset cache if resetCache function returns true. Defaults() => false.- Arguments:
action(Object): An action.state(Object): The current state of the Store.
- Returns:
- (Boolean): If
true, reset all cache.
- (Boolean): If
- Arguments:
Returns
- (Function): Redux middleware.