joao-fontenele / stable-cache

A redis cache library, with producer resilience easily configurable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add minimumRps parameter on Cache instance demonstration (README)

limafm opened this issue · comments

Tried to use the lib, but for some reason the cb was not working propertly.
Reading the code, I noticed that the minimumRps parameter existed and that it was a source of my problem.

So, I'm suggesting to add this parameter just like that:

const cache = new Cache({
  redis, // required to inject a redis client
  options: { // everything is optional from here
    name: 'someService', // name of the service the cache will handle, useful for RTA
    circuitBreaker: { // circuit breaker config for the service
      // percentage of failing producer requests to trigger the circuit breaker
      threshold: 0.2,
      // time window to be considered by the threshold, in milliseconds
      duration: 10000,
      // attempt to half open the circuit after this time in milliseconds
      halfOpenAfter: 20000,
      // don't open the circuit if there's less than this amount of RPS.
      // This avoids opening the circuit, during failures in low load periods.
      minimumRps: 5,
    },
  },
});

(instructions copy-pasted from classes/policies)