(self, key: str, payload: Dict, *, ttl: int)
| 57 | return data.get("payload") |
| 58 | |
| 59 | def save(self, key: str, payload: Dict, *, ttl: int) -> None: |
| 60 | path = self._path_for(key) |
| 61 | path.parent.mkdir(parents=True, exist_ok=True) |
| 62 | data = { |
| 63 | "fetched_at": isoformat(), |
| 64 | "expires_at": time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(time.time() + ttl)), |
| 65 | "payload": payload, |
| 66 | } |
| 67 | with path.open("w", encoding="utf-8") as handle: |
| 68 | json.dump(data, handle, ensure_ascii=False, indent=2) |
| 69 | |
| 70 | |
| 71 | @dataclass |
no test coverage detected