Now with more cache
Caching and the Beginning of Rolling Stats
This release introduces caching to a circuit. It's simple. Just provide { cache: true }
in your options when creating the circuit, and the circuit will cache the first successful response it gets, and always use that. You can clear the cached value by calling circuit.clearCache()
. This may be useful in situations where up-to-the-millisecond values are not required. For example, a badge icon that displays a message count may choose to cache the value, and only update it once every 5 seconds.
// The circuit will cache the message count
const circuit = circuitBreaker( getMessageCount, { cache: true } );
// reset the cache every 5 seconds
const interval = setInterval( () => circuit.clearCache, 5000 );
Rolling stats have also been introduced in this release. This replaces the existing cumulative behavior of a circuit's status, in favor of snapshots every X
milliseconds, where X
defaults to 10000, e.g. 10 seconds. This allows for rolling average calculations on important statistics for Hystrix dashboard, and is in pursuit of
#32 (but does not complete it).
Bug Fixes
- circuit should emit failure event on fallback (f2594d8)
- include the error when emitting the 'fallback event' (40eb2eb)
- promise should reject when action throws (58dab98)
- typo copy past duplicated property (54a27b9)