Skip to content

fix(client): evict expired cache entries and bound cache size with LRU - #35

Open
techkayacodes wants to merge 1 commit into
priompt:mainfrom
techkayacodes:fix/client-cache-eviction
Open

techkayacodes wants to merge 1 commit into
priompt:mainfrom
techkayacodes:fix/client-cache-eviction

Conversation

@techkayacodes

Copy link
Copy Markdown
Contributor

Evicts expired cache entries and bounds client cache size with LRU eviction in PromptClient.

Changes

  • Switch PromptClient._cache to an OrderedDict guarded by _cache_lock and add an optional cache_max_entries=1024 parameter (rejecting non-positive values).
  • Factor cache reads and writes into _cache_get() and _cache_set() shared by get() and list():
    • Expired entries are deleted on lookup and pruned on insert so long-running processes with distinct URIs/prefixes stay bounded.
    • Hits refresh LRU order via move_to_end(), and inserts exceeding cache_max_entries evict any remaining expired entries first, then the least recently used entry.
  • Add deterministic unit tests in tests/test_client.py covering expired get()/list() cleanup, deletion on lookup when a refetch fails, LRU eviction with cache_max_entries, and validation of non-positive limits.

Verification

  • Verified locally in Python 3.12 against a fake monotonic clock and stub covering 1,000 expiring get() calls, 100 expiring list() calls, LRU eviction, and invalid limit rejection.

Closes #26

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for the pull request, @techkayacodes! Before a maintainer reviews it, please check the contribution process:

Pull requests that do not follow the process may be closed.

This branch has not been deployed

No deployments
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.

Client cache never evicts expired entries

1 participant