Get cached value if it exists and hasn't expired
(self, key: str, timeout_seconds: int | None = None)
| 113 | self._compute_locks_lock = threading.Lock() |
| 114 | |
| 115 | def get(self, key: str, timeout_seconds: int | None = None) -> Any | None: |
| 116 | """Get cached value if it exists and hasn't expired""" |
| 117 | with self._cache_lock: |
| 118 | if key not in self._cache: |
| 119 | return None |
| 120 | |
| 121 | entry = self._cache[key] |
| 122 | |
| 123 | # Check if cache is still valid |
| 124 | if timeout_seconds is not None: |
| 125 | age = (datetime.now() - entry.timestamp).total_seconds() |
| 126 | if age > timeout_seconds: |
| 127 | del self._cache[key] |
| 128 | return None |
| 129 | |
| 130 | return entry.data |
| 131 | |
| 132 | def set(self, key: str, value: Any): |
| 133 | """Set cache value""" |
no outgoing calls