TTL cache backed by cachebox (Rust).
| 9 | |
| 10 | |
| 11 | class 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 | |
| 33 | class LRUCache: |
no outgoing calls
no test coverage detected