Skip to content

Files

Latest commit

Jun 24, 2020
3af9838 · Jun 24, 2020

History

History
58 lines (34 loc) · 1.14 KB

readme.md

File metadata and controls

58 lines (34 loc) · 1.14 KB

Saga Cacher

  • Extends Saga providing caching functionality to TakeEvery

  • TakeEvery takes two new parameters: Cache & CacheTime

How to use

Rather than importing redux-saga effects:

import { put, takeEvery, all, select } from 'redux-saga/effects';

Import the middleware instead:

import { put, takeEvery, all, select } from '@mgarf/saga-cacher';

List Item Caching

This middlware has the ability to do caching on items in a list.

In the event pass key to denote the unique primary key on the items being cached. Then pass that primary key and it will add it to a list with other records under the same event and each list item will have its only individual cache expiration time.

Example

{   
    type: "SPECIFIC_ITEM", 
    id: "1", 
    key: "id"
}

Notes

  • Cache defaults to false
  • Cache Time defaults to 5

Snippet of the overriding function

function* takeEvery(event, worker, cache = false, cacheTime = 5) {

}

Limitations

  • This only overrides takeEvery

  • This is being used for a side project so please test heavily in any implementation it's used in.