Skip to content

Cache Lifecycle and Performance

Ngan Pham edited this page Feb 24, 2026 · 1 revision

Cache Lifecycle and Performance

Lifecycle

  1. A fixture is declared in test context.
  2. FixtureKit generates cache by evaluating fixture definition in adapter isolation.
  3. FixtureKit records touched models and stores SQL restore statements + exposed ids.
  4. Each test mounts cache data and rehydrates exposed records through Repository.

Cache Clearing

At runner start, FixtureKit clears cache_path by default.

  • RSpec start point: before(:suite)
  • Minitest start point: class run_suite before first generation

Preserve Cache

Set FIXTURE_KIT_PRESERVE_CACHE to keep cache files between runs:

FIXTURE_KIT_PRESERVE_CACHE=1 bundle exec rspec

Truthy values are case-insensitive: 1, true, yes.

Performance Notes

  • Cache generation does real app writes once per fixture context.
  • Cache mounting replays SQL in batches per connection with referential integrity disabled during replay.
  • Repository reads are lazy and memoized per exposed name.

Clone this wiki locally