Repository navigation
Open
Labels
Description
Summary
With cache_ttl set, every distinct URI passed to get() and every distinct prefix passed to list() adds an entry to self._cache. Expired entries are ignored on lookup but never deleted; the only removal is the pop in the subscription handler for an accepted reload. The cache grows without bound.
Impact
Long-running processes that touch many URIs or prefixes (multi-tenant services building URIs per customer, tools that browse with many list() prefixes) hold every response they have ever fetched, including full templates, for the life of the process.
Steps to reproduce
pip install priompt-sdk- Run (uses a fake stub so no server is needed):
from priompt_sdk import PromptClient import priompt_sdk.client as mod class Stub: def GetPrompt(self, req, metadata=None): return req.uri now = [0.0] mod.time.monotonic = lambda: now[0] c = PromptClient(host="localhost:1", cache_ttl=1) c._stub = Stub() for i in range(10_000): c.get(f"priompt://acme/p{i}") now[0] += 2 # every previous entry is now expired print(len(c._cache))
Actual: 10000, although at most one entry is still valid.
Expected behavior
Expired entries are removed, and the cache size stays bounded (optionally by a configurable maximum).
Where to look
priompt_sdk/client.py#L92-L97the plain-dict cachepriompt_sdk/client.py#L110-L118get()lookup/insert; expired hits are skipped but keptpriompt_sdk/client.py#L130-L139list()lookup/insert, same patternpriompt_sdk/client.py#L215-L216the only deletion
Suggested approach
- Factor the lookup into a small helper that deletes an expired entry when it finds one.
- Add an optional
cache_max_entries(e.g. default 1024) and evict the oldest entry on insert, using anOrderedDictwithmove_to_endon hit (LRU). - Note: the subscription handler runs on another thread; a plain
dictis fine for single operations, but if the helper becomes read-modify-write, guard it with athreading.Lock.
Getting started
- Set up:
pip install -e . pytest, then runpytest -qfrom the repo root. - The cache lives in
PromptClientinpriompt_sdk/client.py.tests/test_client.pyalready has aFakeStuband aclockfixture that controlstime.monotonic, so TTL tests are deterministic; add eviction tests next to the existing cache tests.
Acceptance criteria
- Expired entries are removed from
_cachefor bothget()andlist()keys. - The cache has a bounded size, with eviction tested.
- Existing cache tests still pass.
Activity
techkayacodes commentedon Dec 2, 2026
Hi! I'd like to claim this issue — I've opened PR #35 switching
PromptClient._cacheto a lock-guardedOrderedDictwith expired-entry eviction on lookup/insert, an optionalcache_max_entries=1024LRU cap, and deterministic TTL/LRU unit tests. Happy to adjust anything after assignment!