Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #691 - Obsolete THUMBNAIL_KVSTORE #692

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions docs/reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^
Expand All @@ -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
<https://github.com/andymccurdy/redis-py/>`_.
Expand Down Expand Up @@ -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``
Expand Down
5 changes: 4 additions & 1 deletion docs/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://docs.djangoproject.com/en/dev/topics/cache/>`_ setup properly using
<https://docs.djangoproject.com/en/stable/topics/cache/>`_ setup properly using
memcached. This cache needs to be really fast so **using anything else than
memcached is not recommended**.

Expand Down
12 changes: 12 additions & 0 deletions sorl/thumbnail/kvstores/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions sorl/thumbnail/kvstores/cached_db_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class EMPTY_VALUE:


class KVStore(KVStoreBase):
def __init__(self):
super().__init__()
_cached_db_kvstore = True

@property
def cache(self):
Expand Down
Loading