Skip to content

Add optional Active Record feature-state cache - #198

Merged
michal-granec merged 6 commits into
masterfrom
add/active-record-feature-cache
Sep 16, 2026
Merged

michal-granec merged 6 commits into
masterfrom
add/active-record-feature-cache

Conversation

@michal-granec

@michal-granec michal-granec commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #197.

Adds an optional per-feature in-process TTL cache to rollout-active_record-adapter.

Summary

  • Enable with cache_ttl_seconds: 10.
  • Cache FeatureState by name, including missing features.
  • Refresh an entry on the next read after the TTL.
  • Mutations always use the database and invalidate the local entry after commit.
  • Skip cache reads inside an open database transaction.
  • History, existence checks, and feature listings remain uncached.

Test plan

  • Cache specs for hits, expiry, isolation, bulk reads, writes, and transactions
  • Backend contract also runs with cache_ttl enabled

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Concurrent reads can restore invalidated stale values, and expired cache entries can accumulate without bound.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds an optional per-adapter TTL cache for Active Record feature-state reads.

Changes:

  • Adds thread-safe feature caching with TTL and cloning.
  • Invalidates cached state after committed mutations.
  • Adds cache documentation and coverage for reads, writes, transactions, and configuration.
File summaries
File Description
lib/rollout/adapters/active_record.rb Integrates caching and commit-aware invalidation.
lib/rollout/active_record/feature_cache.rb Implements the in-process TTL cache.
spec/cache_spec.rb Tests cache behavior and transactions.
spec/configuration_spec.rb Tests TTL validation.
spec/backend_contract_spec.rb Runs backend contracts with caching enabled.
README.md Documents cache configuration and semantics.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rollout-active_record-adapter/lib/rollout/adapters/active_record.rb Outdated
Comment thread rollout-active_record-adapter/lib/rollout/adapters/active_record.rb Outdated
Cache FeatureState by name with a configurable TTL. Mutations still
read the database, and cache reads are skipped inside transactions.
Reject in-flight fills after local writes, bypass AR query cache only
when the TTL cache is enabled, and defer invalidation until the outer
transaction commits.
@michal-granec
michal-granec force-pushed the add/active-record-feature-cache branch from b091361 to 22e3616 Compare September 16, 2026 11:38
@michal-granec
michal-granec changed the base branch from add/redis-active-record-migration to master September 16, 2026 11:49
AR 7.1 does not accept uncached(dirties: false). Write around the SQL
cache in a version-safe way and prime it before asserting TTL refresh.
7.1 always clears the SQL cache on writes, so those examples cannot
prime a stale result. Keep them on 7.2+ where uncached(dirties: false)
is available.
Make the unit explicit in the adapter option, FeatureCache, specs, and
README.
@michal-granec
michal-granec merged commit 4ee2de9 into master Sep 16, 2026
24 checks passed
@michal-granec
michal-granec deleted the add/active-record-feature-cache branch September 16, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants