feat: Implement advanced cache management features - #4
Open
frenzel-ai-dev wants to merge 5 commits into
Open
Conversation
This commit introduces several enhancements to the job caching mechanism:
1. **Cache Size Limits & LRU Eviction:**
* The `JobCache` now supports limits based on the maximum number of files (`max_cache_files`) and the total cache size in bytes (`max_cache_size_bytes`).
* An LRU (Least Recently Used) eviction policy has been implemented to automatically remove older cache entries when these limits are exceeded.
* File access times are updated on cache hits to ensure the LRU logic is accurate.
2. **Granular Cache Clearing:**
* The `clear_cache` method in `JobCache` has been enhanced to allow clearing by specific `site`, `query`, and `location`.
* A new method, `clear_expired_cache`, has been added to remove only cache entries that have passed their defined expiration time.
3. **Cache Management CLI:**
* A new CLI script, `job_recommender/manage_cache_cli.py`, provides command-line tools for cache administration.
* You can now clear the cache (entirely, or filtered by site/query/location) and clear only expired entries via this CLI.
* The CLI accepts a `--cache-dir` argument to specify the cache directory, which also aids in testing.
4. **Unit Tests:**
* Comprehensive unit tests have been added for the new cache eviction policies (file count, size, LRU logic), granular clearing functions, and CLI commands.
* All tests are passing.
5. **Linting & Fixes:**
* Critical linting errors (e.g., undefined names) have been resolved.
* Some stylistic linting issues (line length, unused imports) remain but do not impact functionality.
These changes provide more robust and flexible control over the caching system, preventing uncontrolled growth and allowing for more targeted cache management.
There was a problem hiding this comment.
Pull Request Overview
This PR adds advanced management to the job caching system, including LRU eviction based on file count and total size, granular and expired-cache clearing methods, a new CLI for cache administration, and accompanying unit tests.
- Introduce
max_cache_filesandmax_cache_size_byteslimits with LRU eviction inJobCache. - Enhance
clear_cacheto filter by site/query/location and addclear_expired_cache. - Provide a
manage_cache_cli.pyscript with--cache-dir, plus comprehensive tests.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_manage_cache_cli.py | CLI tests for clear and clear-expired commands with --cache-dir. |
| tests/test_cache.py | Unit tests for caching, eviction, clearing, and expiration logic. |
| job_recommender/cache.py | Added file/size limits, LRU eviction, and refined clear methods. |
| job_recommender/manage_cache_cli.py | New CLI script supporting cache management commands. |
| job_recommender/parallel_scraper.py | Added (unused) rich.progress import. |
| job_recommender/job_scraper.py | Moved ParallelJobScraper import into main() to break a cycle. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces several enhancements to the job caching mechanism:
Cache Size Limits & LRU Eviction:
JobCachenow supports limits based on the maximum number of files (max_cache_files) and the total cache size in bytes (max_cache_size_bytes).Granular Cache Clearing:
clear_cachemethod inJobCachehas been enhanced to allow clearing by specificsite,query, andlocation.clear_expired_cache, has been added to remove only cache entries that have passed their defined expiration time.Cache Management CLI:
job_recommender/manage_cache_cli.py, provides command-line tools for cache administration.--cache-dirargument to specify the cache directory, which also aids in testing.Unit Tests:
Linting & Fixes:
These changes provide more robust and flexible control over the caching system, preventing uncontrolled growth and allowing for more targeted cache management.