Get cached data with TTL check and access tracking.
(self, key: str)
| 41 | self._misses = 0 |
| 42 | |
| 43 | def get(self, key: str) -> Optional[bytes]: |
| 44 | """Get cached data with TTL check and access tracking.""" |
| 45 | with self._lock: |
| 46 | entry = self._entries.get(key) |
| 47 | if not entry: |
| 48 | self._misses += 1 |
| 49 | return None |
| 50 | |
| 51 | # Check TTL |
| 52 | if time.time() - entry.timestamp > self._ttl_seconds: |
| 53 | self._delete_entry(key, entry) |
| 54 | self._misses += 1 |
| 55 | return None |
| 56 | |
| 57 | # Update access count and move to end (recently used) |
| 58 | entry.access_count += 1 |
| 59 | self._entries.move_to_end(key) |
| 60 | self._hits += 1 |
| 61 | return entry.data |
| 62 | |
| 63 | def put(self, key: str, data: bytes) -> None: |
| 64 | """Put data in cache with size tracking.""" |
no test coverage detected