Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recruit-tech/redux-effects-fetchr-cache
caching middleware for redux-effects-fetchr
https://github.com/recruit-tech/redux-effects-fetchr-cache
Last synced: about 11 hours ago
JSON representation
caching middleware for redux-effects-fetchr
- Host: GitHub
- URL: https://github.com/recruit-tech/redux-effects-fetchr-cache
- Owner: recruit-tech
- License: mit
- Created: 2016-07-22T13:00:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T08:30:01.000Z (almost 5 years ago)
- Last Synced: 2024-09-21T22:42:02.477Z (about 2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 7
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-effects-fetchr
Caching middleware for
[redux-effects-fetchr](https://www.npmjs.com/package/redux-effects-fetchr).## Installation
```
npm install --save redux-effects-fetchr-cache
```## Usage
Installing the middleware:
```javascript
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](https://www.npmjs.com/package/lru-cache)
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.
* `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.
* `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.##### Returns
* *(Function)*: Redux middleware.