Skip to content

feat: Implement advanced cache management features - #4

Open
frenzel-ai-dev wants to merge 5 commits into
mainfrom
feat/cache-improvements
Open

feat: Implement advanced cache management features#4
frenzel-ai-dev wants to merge 5 commits into
mainfrom
feat/cache-improvements

Conversation

@frenzel-ai-dev

Copy link
Copy Markdown
Owner

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.

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.
@frenzel-ai-dev
frenzel-ai-dev requested a review from Copilot May 26, 2025 22:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_files and max_cache_size_bytes limits with LRU eviction in JobCache.
  • Enhance clear_cache to filter by site/query/location and add clear_expired_cache.
  • Provide a manage_cache_cli.py script 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.

Comment thread job_recommender/cache.py Outdated
Comment thread job_recommender/manage_cache_cli.py Outdated
Comment thread job_recommender/parallel_scraper.py Outdated
Comment thread job_recommender/job_scraper.py Outdated
frenzel-ai-dev and others added 4 commits May 26, 2025 18:55
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>
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