2024-11-27 14:54:54 -08:00
|
|
|
from datetime import timedelta
|
|
|
|
|
from typing import Any, Union
|
2024-08-23 11:17:01 +08:00
|
|
|
|
|
|
|
|
from cachetools import TTLCache
|
|
|
|
|
|
|
|
|
|
from skyvern.forge.sdk.cache.base import CACHE_EXPIRE_TIME, MAX_CACHE_ITEM, BaseCache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LocalCache(BaseCache):
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
|
self.cache: TTLCache = TTLCache(maxsize=MAX_CACHE_ITEM, ttl=CACHE_EXPIRE_TIME.total_seconds())
|
|
|
|
|
|
|
|
|
|
async def get(self, key: str) -> Any:
|
|
|
|
|
if key not in self.cache:
|
|
|
|
|
return None
|
|
|
|
|
value = self.cache[key]
|
|
|
|
|
return value
|
|
|
|
|
|
2024-11-27 14:54:54 -08:00
|
|
|
async def set(self, key: str, value: Any, ex: Union[int, timedelta, None] = CACHE_EXPIRE_TIME) -> None:
|
2024-08-23 11:17:01 +08:00
|
|
|
self.cache[key] = value
|