Skip to content

Clear MemoryCache for inline fixtures after context finishes#31

Merged
ngan merged 1 commit intomainfrom
np-clear-memory-cache-for-inline-fixtures
Feb 26, 2026
Merged

Clear MemoryCache for inline fixtures after context finishes#31
ngan merged 1 commit intomainfrom
np-clear-memory-cache-for-inline-fixtures

Conversation

@ngan
Copy link
Collaborator

@ngan ngan commented Feb 26, 2026

Summary

  • Extract FileCache and MemoryCache out of Cache into their own classes
  • Add Cache#clear_memory to nil out @data, allowing GC to reclaim MemoryCache
  • Add Fixture#finish which calls clear_memory only for anonymous (inline) fixtures — named fixtures retain their cache since they may be shared across contexts
  • Hook finish into RSpec append_after(:context) and Minitest run_suite

The key invariant: a finished fixture can still be mounted again — it re-hydrates from FileCache instead of using the in-memory copy.

Test plan

  • Cache#clear_memory nils out @data
  • After clear_memory, exists? still returns true (falls through to file check)
  • After clear_memory, load re-reads from FileCache
  • Fixture#finish clears memory for anonymous fixtures
  • Fixture#finish does not clear memory for named fixtures
  • A finished anonymous fixture can still be mounted
  • RSpec append_after(:context) hook calls finish
  • Minitest run_suite calls finish after super
  • Full suite passes (157 examples, 0 failures)

🤖 Generated with Claude Code

After a context/suite finishes running, inline (anonymous) fixtures hold a
MemoryCache reference that will never be used again. Named fixtures are shared
and keep their memory. Releasing the MemoryCache for inline fixtures allows
GC to reclaim the SQL statements and exposed mappings.

- Extract FileCache and MemoryCache into their own classes
- Add Cache#clear_memory to nil out @DaTa
- Add Fixture#finish which calls clear_memory for anonymous fixtures
- Hook finish into RSpec append_after(:context) and Minitest run_suite

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ngan ngan merged commit 452d96e into main Feb 26, 2026
8 checks passed
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.

1 participant