Cache backends

The cache backends is used to store references to already created thumbnails in order to avoid unnecessary disk or network usage. The Thumbnail object is cached and will be returned directly in get_thumbnail if the cache returns it.

class thumbnails.cache_backends.BaseCacheBackend[source]

Extendible cache backend that should be used when creating a new cache backend. Subclasses should only override methods prefixed with _.

_get(thumbnail_name)[source]

Backend specific handling of get, should be overridden by subclasses.

Parameters:thumbnail_name – String or list with the name/hash of the thumbnail.
Return type:Thumbnail
_set(thumbnail_name, thumbnail)[source]

Backend specific handling of set, should be overridden by subclasses.

Parameters:
  • thumbnail_name – String with the name of the thumbnail.
  • thumbnail – The Thumbnail object that should be cached.
get(thumbnail_name)[source]

Wrapper for _get, which converts the thumbnail_name to String if necessary before calling _get

Return type:Thumbnail
set(thumbnail)[source]

Wrapper for _set.

class thumbnails.cache_backends.SimpleCacheBackend[source]

Cache backend that stores objects in a dict on the backend instance.

class thumbnails.cache_backends.DjangoCacheBackend[source]

Cache backend that uses Django’s cache.

class thumbnails.cache_backends.RedisCacheBackend[source]

Cache backend that connects to Redis with redis-py. It uses the THUMBNAIL_CACHE_CONNECTION_URI setting as connection configuration. The setting should contain a string on the form: redis://host:port/db, example: redis://127.0.0.1:6379/0 will give the default settings. This backend does not sett time-to-live on the cached items, thus they will be in redis until they are deleted.

If the settings string is not good enough for your configuration, it is possible to extend this backend and override get_settings.

get_settings()[source]

This creates a dict with keyword arguments used to create the redis client. It is used like redis.StrictClient(**self.get_settings()). Thus, if the settings string is not enough to generate the wanted setting you can override this function.

Returns:A dict with keyword arguments for the redis client constructor.