Skip to content

Update file cache size accounting when replacing an entry - #856

Closed
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/overwrite-size
Closed

Update file cache size accounting when replacing an entry#856
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/overwrite-size

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Replacing an existing file cache entry adjusts size accounting by the change in stored bytes, so growth can trigger eviction and shrinkage releases capacity.

Reproduction and evidence

A 128-byte FileStore initialized with a small value reports 15 bytes. Replacing the same key with a 200-character string writes 211 bytes but leaves the reported size at 15, so eviction never runs. Record the previous file size and account for the new-minus-old byte delta after writing.

Dir.mktmpdir do |dir|
  store = Sprockets::Cache::FileStore.new(dir, 128)
  store.set("entry", "short")
  store.set("entry", "x" * 200)
  p Dir.glob(File.join(dir, "**/*.cache")).sum { |path| File.size(path) }
  # Before: 211, above the 128-byte limit. After: 0 after normal eviction.
end

The external checks cover growth, shrinkage, unlimited/limited stores, compressed values, replacing a preexisting entry with a new store instance, retaining unrelated entries after shrinking and serialization failures. Existing cross-process/concurrent-writer accounting remains approximate; this does not claim to make FileStore globally synchronized. Complements #837 (clear accounting), which addresses a different path.

Ruby examples use require "sprockets"; require "tmpdir".

Verification

  • Isolated patch: unchanged full and isolated test tasks each pass 913 tests /4,109 assertions /zero failures/errors /four skips, Ruby 3.2.11 and 4.0.6.
  • 114 focused external checks pass on each Ruby. The overwrite defect reproduces on the release baseline; sorting equivalence is checked against the original algorithm.
  • Full RuboCop: 133 files, zero offenses. Changed syntax passes both Rubies; whitespace checks pass. All Ruby commands use rbenv.
  • Gem build/content comparison preserves 84 paths, version 4.4.1, Ruby >=2.5 and dependency metadata. Only README, CHANGELOG and FileStore differ.

Compatibility and limitations

Breaking changes: none intended. Overgrown replacement entries can now trigger the existing eviction policy, and shrinking entries no longer consume their old capacity. No new dependencies or version upgrades. Based on installed release/current main 49d9f20c00ac7d9a7ee57db058961edcccd86699.

Upstream-only contribution: no application fork pin, deployment or current-master boot claim. No checked-in tests were added or modified under the requesting repository's no-test-edit policy; focused evidence ran externally. Older Ruby/Linux/JRuby verification is left to upstream CI, not claimed locally. Prepared with AI assistance. This is a focused change, not an exhaustive review.

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