Get the value of a key from the cache :param key: :return:
(self, key: str)
| 54 | self._cron_task.cancel() |
| 55 | |
| 56 | def get(self, key: str) -> Optional[Any]: |
| 57 | """ |
| 58 | Get the value of a key from the cache |
| 59 | :param key: |
| 60 | :return: |
| 61 | """ |
| 62 | value, expire_time = self._cache_container.get(key, (None, 0)) |
| 63 | if value is None: |
| 64 | return None |
| 65 | |
| 66 | # If the key has expired, delete it and return None |
| 67 | if expire_time < time.time(): |
| 68 | del self._cache_container[key] |
| 69 | return None |
| 70 | |
| 71 | return value |
| 72 | |
| 73 | def set(self, key: str, value: Any, expire_time: int) -> None: |
| 74 | """ |