fastapi-cache
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: fastapi-cache | ||
| Version: 0.0.5 | ||
| Version: 0.0.6 | ||
| Summary: FastAPI simple cache | ||
@@ -63,6 +63,16 @@ Home-page: https://github.com/comeuplater/fastapi_cache | ||
| * [X] Add tests | ||
| * [ ] Add registry decorator | ||
| * [ ] ~~Add registry decorator~~ | ||
| * [ ] Add dependency for requests caching | ||
| ## Acknowledgments | ||
| * Balburdia | ||
| * xobtoor | ||
| ## Changelog | ||
| * 0.0.6 Added typings for backends. Specific arguments now need to be passed through **kwargs. | ||
| Set default encoding to utf-8 for redis backend, removed default TTL for redis keys. | ||
| Keywords: redis,aioredis,asyncio,fastapi,starlette,cache | ||
| Platform: UNKNOWN | ||
| Description-Content-Type: text/markdown |
@@ -1,12 +0,13 @@ | ||
| from typing import Any, Union | ||
| from typing import TypeVar, Generic, Tuple | ||
| DEFAULT_TIMEOUT = 600 | ||
| KT = TypeVar('KT') | ||
| VT = TypeVar('VT') | ||
| class BaseCacheBackend(object): | ||
| class BaseCacheBackend(Generic[KT, VT]): | ||
| async def add( | ||
| self, | ||
| key: Union[str, int], | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| key: KT, | ||
| value: VT, | ||
| **kwargs | ||
| ) -> bool: | ||
@@ -17,5 +18,6 @@ raise NotImplementedError | ||
| self, | ||
| key: Union[str, int], | ||
| default: Any = None | ||
| ) -> Any: | ||
| key: KT, | ||
| default: VT = None, | ||
| **kwargs | ||
| ) -> VT: | ||
| raise NotImplementedError | ||
@@ -25,11 +27,14 @@ | ||
| self, | ||
| key: Union[str, int], | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| key: KT, | ||
| value: VT, | ||
| **kwargs | ||
| ) -> bool: | ||
| raise NotImplementedError | ||
| async def delete(self, key: Union[str, int]) -> bool: | ||
| async def exists(self, *keys: Tuple[KT]) -> bool: | ||
| raise NotImplementedError | ||
| async def delete(self, key: KT) -> bool: | ||
| raise NotImplementedError | ||
| async def flush(self) -> None: | ||
@@ -36,0 +41,0 @@ raise NotImplementedError |
@@ -1,11 +0,9 @@ | ||
| from typing import Any, Union | ||
| from typing import Any, Hashable, Tuple | ||
| from .base import BaseCacheBackend | ||
| DEFAULT_TIMEOUT = 0 | ||
| CACHE_KEY = 'IN_MEMORY' | ||
| class InMemoryCacheBackend(BaseCacheBackend): | ||
| class InMemoryCacheBackend(BaseCacheBackend[Hashable, Any]): | ||
| def __init__(self): | ||
@@ -16,5 +14,5 @@ self._cache: dict = {} | ||
| self, | ||
| key: Union[str, int], | ||
| key: Hashable, | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| **kwargs, | ||
| ) -> bool: | ||
@@ -29,4 +27,5 @@ if key in self._cache: | ||
| self, | ||
| key: Union[str, int], | ||
| default: Union[str, int] = None | ||
| key: Hashable, | ||
| default: Any = None, | ||
| **kwargs | ||
| ) -> Any: | ||
@@ -37,5 +36,5 @@ return self._cache.get(key, default) | ||
| self, | ||
| key: Union[str, int], | ||
| key: Hashable, | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| **kwargs, | ||
| ) -> bool: | ||
@@ -46,3 +45,8 @@ self._cache[key] = value | ||
| async def delete(self, key: Union[str, int]) -> bool: | ||
| async def exists(self, *keys: Tuple[Hashable]) -> bool: | ||
| return any( | ||
| map(lambda key: key in self._cache, keys) | ||
| ) | ||
| async def delete(self, key: Hashable) -> bool: | ||
| if key not in self._cache: | ||
@@ -49,0 +53,0 @@ return False |
@@ -1,2 +0,2 @@ | ||
| from typing import Any, Optional, Union | ||
| from typing import Union, Any, Optional | ||
@@ -6,13 +6,21 @@ import aioredis | ||
| from .base import BaseCacheBackend, DEFAULT_TIMEOUT | ||
| from .base import BaseCacheBackend | ||
| DEFAULT_ENCODING = 'utf-8' | ||
| DEFAULT_POOL_MIN_SIZE = 5 | ||
| CACHE_KEY = 'REDIS' | ||
| RedisAcceptable = Union[str, int] | ||
| class RedisCacheBackend(BaseCacheBackend): | ||
| def __init__(self, address: str, pool_minsize: int = DEFAULT_POOL_MIN_SIZE) -> None: | ||
| class RedisCacheBackend(BaseCacheBackend[RedisAcceptable, Any]): | ||
| def __init__( | ||
| self, | ||
| address: str, | ||
| pool_minsize: Optional[int] = DEFAULT_POOL_MIN_SIZE, | ||
| encoding: Optional[str] = DEFAULT_ENCODING | ||
| ) -> None: | ||
| self._redis_address = address | ||
| self._redis_pool_minsize = pool_minsize | ||
| self._encoding = encoding | ||
@@ -31,5 +39,5 @@ @property | ||
| self, | ||
| key: Union[str, int], | ||
| key: RedisAcceptable, | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| **kwargs | ||
| ) -> bool: | ||
@@ -56,16 +64,14 @@ """ | ||
| return await client.set(key, value, expire=timeout) | ||
| return await client.set(key, value, **kwargs) | ||
| async def get( | ||
| self, | ||
| key: Union[str, int], | ||
| key: RedisAcceptable, | ||
| default: Any = None, | ||
| encoding: Optional[str] = 'utf-8' | ||
| **kwargs, | ||
| ) -> Any: | ||
| kwargs = {"key": key} | ||
| if encoding is not None: | ||
| kwargs['encoding'] = encoding | ||
| kwargs.setdefault('encoding', self._encoding) | ||
| client = await self._client | ||
| cached_value = await client.get(**kwargs) | ||
| cached_value = await client.get(key, **kwargs) | ||
@@ -76,13 +82,19 @@ return cached_value if cached_value is not None else default | ||
| self, | ||
| key: Union[str, int], | ||
| key: RedisAcceptable, | ||
| value: Any, | ||
| timeout: int = DEFAULT_TIMEOUT | ||
| **kwargs, | ||
| ) -> bool: | ||
| client = await self._client | ||
| return await client.set(key, value, expire=timeout) | ||
| return await client.set(key, value, **kwargs) | ||
| async def delete(self, key: Union[str, int]) -> bool: | ||
| async def exists(self, *keys: Union[RedisAcceptable]) -> bool: | ||
| client = await self._client | ||
| exists = await client.exists(*keys) | ||
| return bool(exists) | ||
| async def delete(self, key: RedisAcceptable) -> bool: | ||
| client = await self._client | ||
| return await client.delete(key) | ||
@@ -89,0 +101,0 @@ |
@@ -1,4 +0,4 @@ | ||
| VERSION = (0, 0, 5) | ||
| VERSION = (0, 0, 6) | ||
| __author__ = 'Ivan Sushkov <comeuplater>' | ||
| __version__ = '.'.join(str(x) for x in VERSION) |
+12
-2
| Metadata-Version: 2.1 | ||
| Name: fastapi-cache | ||
| Version: 0.0.5 | ||
| Version: 0.0.6 | ||
| Summary: FastAPI simple cache | ||
@@ -63,6 +63,16 @@ Home-page: https://github.com/comeuplater/fastapi_cache | ||
| * [X] Add tests | ||
| * [ ] Add registry decorator | ||
| * [ ] ~~Add registry decorator~~ | ||
| * [ ] Add dependency for requests caching | ||
| ## Acknowledgments | ||
| * Balburdia | ||
| * xobtoor | ||
| ## Changelog | ||
| * 0.0.6 Added typings for backends. Specific arguments now need to be passed through **kwargs. | ||
| Set default encoding to utf-8 for redis backend, removed default TTL for redis keys. | ||
| Keywords: redis,aioredis,asyncio,fastapi,starlette,cache | ||
| Platform: UNKNOWN | ||
| Description-Content-Type: text/markdown |
+12
-1
@@ -56,2 +56,13 @@ # FastAPI Cache | ||
| * [X] Add tests | ||
| * [ ] Add registry decorator | ||
| * [ ] ~~Add registry decorator~~ | ||
| * [ ] Add dependency for requests caching | ||
| ## Acknowledgments | ||
| * Balburdia | ||
| * xobtoor | ||
| ## Changelog | ||
| * 0.0.6 Added typings for backends. Specific arguments now need to be passed through **kwargs. | ||
| Set default encoding to utf-8 for redis backend, removed default TTL for redis keys. |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
15148
10.48%208
9.47%