Add circuit breaker for external store adapters (v1.6.0)#61
Merged
Conversation
- `SafeMemoize::Stores::CircuitBreaker` — Stores::Base wrapper with three-state circuit breaker (closed/open/half_open); reads return MISS and writes are no-ops when open, falling back to the per-instance hash - `circuit_breaker:` option on `memoize` auto-wraps the configured store; accepts `true` (defaults: error_threshold 5, probe_interval 30 s) or a Hash with custom values; raises if no store is configured - Does not double-wrap a store already wrapped in CircuitBreaker - Successful calls in closed state reset the consecutive error counter - `circuit_breaker:` accepted by `safe_memoize_options` as a class default - 32 new tests covering state transitions, fallback behavior, introspection, validation, and the memoize option Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update CHANGELOG, ROADMAP, and README for Stores::CircuitBreaker and the circuit_breaker: memoize option. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SafeMemoize::Stores::CircuitBreaker— aStores::Basewrapper that protects any external store adapter with a three-state circuit breaker. When the store raises, reads returnMISS(triggering the per-instance fallback cache) and writes are no-ops, so callers never see exceptions.circuit_breaker:option onmemoize— auto-wraps the configuredstore:adapter; acceptstruefor defaults (error_threshold: 5,probe_interval: 30 s) or a Hash to customise; also accepted bysafe_memoize_optionsas a class-wide default.CircuitBreaker; raisesArgumentErrorif no store is configured.States:
:closed(normal, errors counted) →:open(store bypassed until probe interval elapses) →:half_open(probe: success closes circuit, failure re-opens and resets timer). Any success in:closedresets the consecutive error counter so transient blips don't accumulate.Test plan
bundle exec rake— 865 examples, 0 failures, lint cleanreset!, validation errors,circuit_breaker:memoize option (true / Hash / invalid), no double-wrapping, end-to-end fallback to per-instance cache🤖 Generated with Claude Code