Skip to content

Fix disk cache cost tracking and purge edge cases#2

Merged
naftaly merged 1 commit intomainfrom
fix/disk-cache-cost-tracking
Nov 30, 2025
Merged

Fix disk cache cost tracking and purge edge cases#2
naftaly merged 1 commit intomainfrom
fix/disk-cache-cost-tracking

Conversation

@naftaly
Copy link
Copy Markdown
Owner

@naftaly naftaly commented Nov 30, 2025

Summary

  • Fix disk cache not subtracting old file size when overwriting, causing cost to accumulate incorrectly
  • Fix URL resource value caching returning stale file sizes after writes
  • Fix items being lost from cost-based purge consideration during staleness purge
  • Fix potential cost drift when file size read fails but delete succeeds
  • Unify purge threshold behavior between memory and disk caches

Test plan

  • Added testOverwriteExistingKeyOnDisk
  • Added testOverwriteExistingKeyOnCombinedCache
  • Added testMultipleOverwritesOnDisk
  • All existing tests pass

- Fix overwrite bug where old file size wasn't subtracted from cost
- Fix URL resource value caching issue when reading new file size
- Preserve items without valid dates for cost-based purge consideration
- Preserve non-stale items for cost-based purge consideration
- Fix potential cost drift in deleteItem when size read fails
- Make purge threshold consistent (purge when over limit, not at limit)
- Add tests for disk and combined cache overwrites
@naftaly naftaly marked this pull request as ready for review November 30, 2025 01:07
@github-actions
Copy link
Copy Markdown

🚀 Arsenal Cache Performance Benchmarks

Multi-layer caching with LRU eviction and disk persistence

Test Hardware: Apple M1 (Virtual), 7 GB RAM

Memory Cache Operations

Operation Items Time Per-Op Status
Get 1000 146.0ms 146.0 μs ⚠️ OK
Set 1000 143.0ms 143.0 μs ⚠️ OK
Set (with purge) 500 251.0ms 502.0 μs ⚠️ OK

Disk Cache Operations

Operation Items Time Per-Op Status
Get 100 110.0ms 1.10 ms ✅ Excellent
Set 100 139.0ms 1.39 ms ✅ Excellent

Combined Cache (Memory + Disk)

Operation Items Time Per-Op Status
Get (disk→memory promotion) 100 136.0ms 1.36 ms ✅ Excellent
Set (both layers) 100 884.0ms 8.84 ms ✅ Good

Large Items (1 MB each)

Storage Items Time Per-Item Status
Disk 20 150ms 7.5ms ✅ Excellent
Memory 50 124ms 2.5ms ✅ Excellent

Throughput (Mixed Read/Write)

Operation Ops Time Ops/sec Status
Memory (33% write, 67% read) 5,000 129ms 38,760 ⚠️ OK

Clear Operations

Storage Items Time Status
Disk 100 142ms ✅ Good
Memory 1000 121ms ✅ Good

Performance Characteristics

Status Legend

  • Excellent/Good: Optimal performance
  • ⚠️ OK: Acceptable, monitor in production
  • Review: May need optimization

Architecture

  • Memory cache: LRU eviction with cost-based limits
  • Disk cache: File-based with staleness and cost eviction
  • Combined: Automatic disk→memory promotion on read
  • Thread safety: @globalActor isolation via ArsenalActor

Total benchmarks: 12 passed | Generated 2025-11-30 01:10:23

@naftaly naftaly merged commit 3007231 into main Nov 30, 2025
4 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