Hazaar\Cache\Backend\File cache file cleanup
Problem Statement
The current implementation of the file-based cache backend in Hazaar uses B-Tree (.db
) cache files. However, there is no mechanism in place to clean up expired or unused cache files. This leads to an accumulation of old session files over time, especially as session IDs expire, which can result in unnecessary disk usage and potential performance degradation.
Who will benefit?
- System administrators who manage long-running applications with high cache usage.
- Developers who rely on file-based caching and want to prevent excessive disk usage.
- Any application using Hazaar’s file-based cache backend to store session or temporary data.
Benefits and risks
Benefits
- Reduces disk space usage by removing expired cache files.
- Prevents unnecessary filesystem clutter.
- Improves cache efficiency by maintaining only relevant cache files.
Risks
- Improper cleanup logic could lead to unintended data loss.
- Performance impact if cleanup is too frequent or resource-intensive.
Proposed solution
Introduce a cleanup mechanism for B-Tree cache files:
- Implement a metadata file in the cache directory to store the last cleanup timestamp.
- Perform a cleanup operation periodically (e.g., every 60 minutes).
- When a
\Hazaar\Cache\Backend\File
instance destructs, check if a cleanup is due. - If cleanup is due, scan the cache directory for
.db
files and delete any that have been inactive for longer than a safe threshold (e.g., a few minutes beyond their expected expiration time).
Priority/Severity
-
High (This will bring a huge increase in performance/productivity/usability/legislative cover) -
Medium (This will bring a good increase in performance/productivity/usability) -
Low (anything else e.g., trivial, minor improvements)
Edited by Jamie Carl