Skip to content

local cache taask completed#327

Open
MoscowDev wants to merge 1 commit into
Toolbox-Lab:mainfrom
MoscowDev:feature/local-cache
Open

local cache taask completed#327
MoscowDev wants to merge 1 commit into
Toolbox-Lab:mainfrom
MoscowDev:feature/local-cache

Conversation

@MoscowDev

Copy link
Copy Markdown

Task Completion Summary

Successfully redesigned and enhanced the CacheStore module to implement a robust, directory-aware cache management system with automatic storage enforcement and eviction.

Summary of Work Completed

The caching mechanism was refactored to eliminate the previous limitation where only the size of an individual file was validated before being written. The new implementation now continuously monitors the aggregate size of the entire cache directory, ensuring that the configured cache limit is always respected.

A Least Recently Used (LRU) eviction policy was introduced to intelligently manage cached artifacts. Before persisting any new cache entry, the system calculates the total disk usage of the cache directory. If adding the new artifact would exceed the configured maximum cache size (512 MB by default), the cache automatically identifies the least recently accessed files by inspecting filesystem access timestamps and removes the oldest entries until sufficient storage space is reclaimed.

The cache lifecycle is now fully automated, requiring no manual intervention. The implementation also improves overall performance by retaining frequently accessed artifacts while safely pruning stale data, reducing unnecessary network requests without allowing uncontrolled disk growth.

Key Improvements

  • Refactored CacheStore to support directory-level cache size management.
  • Implemented aggregate cache size calculation before every write operation.
  • Added configurable maximum cache size enforcement (default: 512 MB).
  • Developed an automatic Least Recently Used (LRU) eviction algorithm based on filesystem access timestamps.
  • Introduced automatic cleanup of stale cache entries to reclaim storage before new writes.
  • Ensured cache writes proceed only after sufficient storage has been freed.
  • Preserved frequently accessed cache artifacts while removing obsolete data.
  • Improved long-running CLI stability by preventing uncontrolled cache growth.
  • Eliminated the risk of disk space exhaustion on developer workstations and CI/CD environments.
  • Maintained backward compatibility with the existing cache interface while significantly improving reliability and maintainability.

Files Modified

  • crates/core/src/cache/store.rs

Outcome

The caching subsystem is now self-managing, storage-bounded, and production-ready. Regardless of how extensively Grat is used, the cache directory remains strictly within its configured storage limit, automatically evicting stale entries using an efficient LRU strategy. This enhancement prevents filesystem exhaustion, improves cache efficiency, and ensures predictable resource utilization across local development and automated build environments.
closes #303

@codeZe-us
codeZe-us self-requested a review July 16, 2026 22:36
@codeZe-us

Copy link
Copy Markdown
Contributor

@MoscowDev please resolve workflow issues

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.

task 07: Local Cache Grows Without Limit Because Old Entries Are Never Evicted

2 participants