From 56562eb42679f2bbb173b03f3f7edb215147b74a Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 1 Mar 2022 09:38:36 +0100 Subject: [PATCH] Fixes #691 - Obsolete THUMBNAIL_KVSTORE --- CHANGES.rst | 4 ++++ docs/reference/settings.rst | 21 +++++++++++++++++--- docs/requirements.rst | 5 ++++- sorl/thumbnail/kvstores/base.py | 12 +++++++++++ sorl/thumbnail/kvstores/cached_db_kvstore.py | 3 +-- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c075c03d9..0a6034fc8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,10 @@ Changes ======= +Unreleased +========== +* Deprecated ``THUMBNAIL_KVSTORE``. Only the Django cache-based store will be + used in a future version. * Add support for Django 5.0 and 5.1 * Drop support for Django 3.2, 4.0 and 4.1 diff --git a/docs/reference/settings.rst b/docs/reference/settings.rst index 7d34c2f12..3988f6ad2 100644 --- a/docs/reference/settings.rst +++ b/docs/reference/settings.rst @@ -31,13 +31,20 @@ your own implementation. - Default: ``'sorl.thumbnail.kvstores.cached_db_kvstore.KVStore'`` +.. deprecated:: 12.11.0 + + Using any other KVStore than the Cached Db KVStore is deprecated. + Please configure the cache that suits your use case at Django level and set + this cache alias in ``THUMBNAIL_CACHE``. + sorl-thumbnail needs a Key Value Store to :doc:`/operation`. sorl-thumbnail ships with support for three Key Value Stores: Cached DB --------- ``sorl.thumbnail.kvstores.cached_db_kvstore.KVStore``. This is the default and -preferred Key Value Store. +preferred Key Value Store. It uses the cache configured at the Django project +level. Features ^^^^^^^^ @@ -50,6 +57,11 @@ Features Redis ----- +From Django 4.0, you can configure a Redis cache at Django level and then use +the Cached DB store while using the configured cache alias in the +``THUMBNAIL_CACHE`` setting. Therefore the Redis store in sorl-thumbnail and its +associated ``THUMBNAIL_REDIS*`` settings maybe removed in the future. + ``sorl.thumbnail.kvstores.redis_kvstore.KVStore``. It requires you to install a Redis server as well as a `redis python client `_. @@ -241,8 +253,11 @@ Only applicable for the Cached DB Key Value Store. - Default: ``'default'`` -Cache configuration for Cached DB Key Value Store. Defaults to the ``'default'`` cache -but some applications might have multiple cache clusters. +Django configured cache alias to use for Cached DB Key Value Store. Defaults to +the ``'default'`` cache but you can use any other cache configured in the Django +project. + +- ``https://docs.djangoproject.com/en/stable/topics/cache/`` ``THUMBNAIL_KEY_PREFIX`` diff --git a/docs/requirements.rst b/docs/requirements.rst index 9ab3e868d..c39851f69 100644 --- a/docs/requirements.rst +++ b/docs/requirements.rst @@ -18,10 +18,13 @@ a **cached database** which requires no special installation to your normal Django setup besides installing a proper cache like memcached **or** you can setup **redis** which requires a little bit more work. +Since Django 4.0, the Redis cache can be configured at Django level, so any +alternative Key Value Store in sorl-thumbnail is now deprecated. + Cached DB --------- All you need to use the cached database key value store is a database and `cache -`_ setup properly using +`_ setup properly using memcached. This cache needs to be really fast so **using anything else than memcached is not recommended**. diff --git a/sorl/thumbnail/kvstores/base.py b/sorl/thumbnail/kvstores/base.py index 97958be14..f4f247514 100644 --- a/sorl/thumbnail/kvstores/base.py +++ b/sorl/thumbnail/kvstores/base.py @@ -1,3 +1,5 @@ +import warnings + from sorl.thumbnail.conf import settings from sorl.thumbnail.helpers import ThumbnailError, deserialize, serialize from sorl.thumbnail.images import deserialize_image_file, serialize_image_file @@ -18,6 +20,16 @@ def del_prefix(key): class KVStoreBase: + def __init__(self): + if not getattr(self, '_cached_db_kvstore', False): + warnings.warn( + "Using any other KVStore than Cached Db KVStore is deprecated. " + "Please configure the cache that suits your use case at Django " + "level and set this cache alias in THUMBNAIL_CACHE.", + DeprecationWarning, + stacklevel=3, + ) + def get(self, image_file): """ Gets the ``image_file`` from store. Returns ``None`` if not found. diff --git a/sorl/thumbnail/kvstores/cached_db_kvstore.py b/sorl/thumbnail/kvstores/cached_db_kvstore.py index f536ee748..6290c89fa 100644 --- a/sorl/thumbnail/kvstores/cached_db_kvstore.py +++ b/sorl/thumbnail/kvstores/cached_db_kvstore.py @@ -10,8 +10,7 @@ class EMPTY_VALUE: class KVStore(KVStoreBase): - def __init__(self): - super().__init__() + _cached_db_kvstore = True @property def cache(self):