tgram_dnd.caching package¶
Submodules¶
tgram_dnd.caching.base module¶
- class tgram_dnd.caching.base.BaseCache[source]¶
Bases:
object- get(key: str) Any | None[source]¶
get the CachedItem by key if has not expierd
- Parameters:
key (str) – the item key
- Returns:
Optional[Any]
- get_or_create(key: str, value: Callable, ttl: int = None) CachedItem[source]¶
get the CachedItem by key, and if not exists a new CachedItem will be created and returned
- Parameters:
ket (str) – the item key
value (Callable) – the function that will retrive the item value (in case the item does not exist/expired)
ttl (int, optional) – item time_to_live, defaults to self.default_ttl
- Returns:
- set(key: str, value: Any, ttl: int = None) CachedItem | None[source]¶
create a CachedItem with the ttl specified or the default_tll
- Parameters:
key (str) – the item key
value (Any) – the cached value
ttl (int, optional) – item time_to_live, defaults to self.default_ttl
- Returns:
Optional[
tgram_dnd.caching.cached_item.CachedItem]
tgram_dnd.caching.cached_item module¶
tgram_dnd.caching.memory module¶
- class tgram_dnd.caching.memory.MemoryCache(default_ttl: int = 10)[source]¶
Bases:
BaseCacheA Memory cache to store temporary items
- Parameters:
default_ttl (int, optional) – the default time_to_live in seconds for each item, defaults to 10
- get(key: str) Any | None[source]¶
get the CachedItem by key if has not expired
- Parameters:
key (str) – the item key
- Returns:
the cached value
- Return type:
Optional[Any]
- async get_or_create(key: str, value: Callable, ttl: int = None) CachedItem[source]¶
get the CachedItem by key, and if not exists a new CachedItem will be created and returned
- Parameters:
ket (str) – the item key
value (Callable) – the function that will retrieve the item value (in case the item does not exist/expired)
ttl (int, optional) – item time_to_live, defaults to self.default_ttl
- Returns:
The cached Value
- Return type:
Any
- set(key: str, value: Any, ttl: int = None) CachedItem | None[source]¶
create a CachedItem with the ttl specified or the default_tll
- Parameters:
key (str) – the item key
value (Any) – the cached value
ttl (int, optional) – item time_to_live, defaults to self.default_ttl
- Returns:
Optional[
tgram_dnd.caching.cached_item.CachedItem]