Skip to content

Now with more cache

Compare
Choose a tag to compare
@lance lance released this 30 Mar 13:06
· 656 commits to main since this release
v0.6.0
3657436

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)

Features

  • add basic rolling stats to a circuit (8fb9561)
  • Add caching capability to circuits (6c3144f)
  • Add caching capability to circuits (0b717f6)
  • Applying code review (6a0f7ff)
  • Applying code review (8445a24)
  • circuits now have a name based on the action (f08d46e)