svg conversion (#717)

This commit is contained in:
LawyZheng
2024-08-23 11:17:01 +08:00
committed by GitHub
parent e5b0d734b8
commit 76ee91ecdd
6 changed files with 150 additions and 1 deletions

16
skyvern/forge/sdk/cache/base.py vendored Normal file
View File

@@ -0,0 +1,16 @@
from abc import ABC, abstractmethod
from datetime import timedelta
from typing import Any
CACHE_EXPIRE_TIME = timedelta(weeks=1)
MAX_CACHE_ITEM = 1000
class BaseCache(ABC):
@abstractmethod
async def set(self, key: str, value: Any) -> None:
pass
@abstractmethod
async def get(self, key: str) -> Any:
pass

14
skyvern/forge/sdk/cache/factory.py vendored Normal file
View File

@@ -0,0 +1,14 @@
from skyvern.forge.sdk.cache.base import BaseCache
from skyvern.forge.sdk.cache.local import LocalCache
class CacheFactory:
__cache: BaseCache = LocalCache()
@staticmethod
def set_cache(cache: BaseCache) -> None:
CacheFactory.__cache = cache
@staticmethod
def get_cache() -> BaseCache:
return CacheFactory.__cache

20
skyvern/forge/sdk/cache/local.py vendored Normal file
View File

@@ -0,0 +1,20 @@
from typing import Any
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]
await self.set(key, value)
return value
async def set(self, key: str, value: Any) -> None:
self.cache[key] = value