Spaces:
Sleeping
Sleeping
Add toolsforgitnotionslack folder as a folder for my code which can be run nativelly and as a fastapi endpoint
4499d27 Download toolsforgitnotionslack/agent/cache.py from AdithyaVardan/GodSpeed: direct link, hf CLI and curl.
- Browser
- Download file 596 Bytes
-
https://huggingface.co/spaces/AdithyaVardan/GodSpeed/resolve/main/toolsforgitnotionslack/agent/cache.py
- Command line
-
hf download hf://spaces/AdithyaVardan/GodSpeed/toolsforgitnotionslack/agent/cache.py
-
curl -L -o cache.py https://huggingface.co/spaces/AdithyaVardan/GodSpeed/resolve/main/toolsforgitnotionslack/agent/cache.py
596 Bytes
| import time | |
| from typing import Optional | |
| class Cache: | |
| def __init__(self, ttl_seconds: int = 300): | |
| self._store: dict[str, tuple[str, float]] = {} | |
| self._ttl = ttl_seconds | |
| def get(self, key: str) -> Optional[str]: | |
| entry = self._store.get(key) | |
| if entry and (time.monotonic() - entry[1]) < self._ttl: | |
| return entry[0] | |
| if entry: | |
| del self._store[key] | |
| return None | |
| def set(self, key: str, value: str) -> None: | |
| self._store[key] = (value, time.monotonic()) | |
| def clear(self) -> None: | |
| self._store.clear() |