This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
__version__ = "4.2.0"
|
__version__ = "4.3.0"
|
||||||
__license__ = "GPL3"
|
__license__ = "GPL3"
|
||||||
__author__ = "Profitroll"
|
__author__ = "Profitroll"
|
||||||
|
|
||||||
|
8
src/libbot/cache/classes/cache.py
vendored
8
src/libbot/cache/classes/cache.py
vendored
@@ -1,5 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
import pymemcache
|
import pymemcache
|
||||||
import redis
|
import redis
|
||||||
@@ -27,16 +27,16 @@ class Cache(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_json(self, key: str, value: Any) -> None:
|
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
# TODO This method must also carry out ObjectId conversion!
|
# TODO This method must also carry out ObjectId conversion!
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_string(self, key: str, value: str) -> None:
|
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_object(self, key: str, value: Any) -> None:
|
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
10
src/libbot/cache/classes/cache_memcached.py
vendored
10
src/libbot/cache/classes/cache_memcached.py
vendored
@@ -69,28 +69,28 @@ class CacheMemcached(Cache):
|
|||||||
def get_object(self, key: str) -> Any | None:
|
def get_object(self, key: str) -> Any | None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def set_json(self, key: str, value: Any) -> None:
|
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
key = self._get_prefixed_key(key)
|
key = self._get_prefixed_key(key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.set(key, _json_to_string(value))
|
self.client.set(key, _json_to_string(value), expire=0 if ttl_seconds is None else ttl_seconds)
|
||||||
logger.debug("Set json cache key '%s'", key)
|
logger.debug("Set json cache key '%s'", key)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_string(self, key: str, value: str) -> None:
|
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
||||||
key = self._get_prefixed_key(key)
|
key = self._get_prefixed_key(key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.set(key, value)
|
self.client.set(key, value, expire=0 if ttl_seconds is None else ttl_seconds)
|
||||||
logger.debug("Set string cache key '%s'", key)
|
logger.debug("Set string cache key '%s'", key)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# TODO Implement binary serialization
|
# TODO Implement binary serialization
|
||||||
def set_object(self, key: str, value: Any) -> None:
|
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def delete(self, key: str) -> None:
|
def delete(self, key: str) -> None:
|
||||||
|
10
src/libbot/cache/classes/cache_redis.py
vendored
10
src/libbot/cache/classes/cache_redis.py
vendored
@@ -69,28 +69,28 @@ class CacheRedis(Cache):
|
|||||||
def get_object(self, key: str) -> Any | None:
|
def get_object(self, key: str) -> Any | None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def set_json(self, key: str, value: Any) -> None:
|
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
key = self._get_prefixed_key(key)
|
key = self._get_prefixed_key(key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.set(key, _json_to_string(value))
|
self.client.set(key, _json_to_string(value), ex=ttl_seconds)
|
||||||
logger.debug("Set json cache key '%s'", key)
|
logger.debug("Set json cache key '%s'", key)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_string(self, key: str, value: str) -> None:
|
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
||||||
key = self._get_prefixed_key(key)
|
key = self._get_prefixed_key(key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.set(key, value)
|
self.client.set(key, value, ex=ttl_seconds)
|
||||||
logger.debug("Set string cache key '%s'", key)
|
logger.debug("Set string cache key '%s'", key)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# TODO Implement binary serialization
|
# TODO Implement binary serialization
|
||||||
def set_object(self, key: str, value: Any) -> None:
|
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def delete(self, key: str) -> None:
|
def delete(self, key: str) -> None:
|
||||||
|
Reference in New Issue
Block a user