MCPcopy Create free account
hub / github.com/pollinations/pollinations / TTLCache

Class TTLCache

apps/polly/src/_cache.py:11–30  ·  view source on GitHub ↗

TTL cache backed by cachebox (Rust).

Source from the content-addressed store, hash-verified

9
10
11class TTLCache:
12 """TTL cache backed by cachebox (Rust)."""
13
14 def __init__(self, maxsize: int = 256, ttl: int = 300):
15 self._c = _CbTTL(maxsize=maxsize, ttl=ttl)
16
17 def get(self, key: str) -> Any | None:
18 try:
19 return self._c[key]
20 except KeyError:
21 return None
22
23 def set(self, key: str, value: Any):
24 self._c[key] = value
25
26 def invalidate(self, key: str | None = None):
27 if key:
28 self._c.pop(key, None)
29 else:
30 self._c.clear()
31
32
33class LRUCache:

Callers 4

doc_embeddings.pyFile · 0.85
__init__Method · 0.85
__init__Method · 0.85
embeddings.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected