Search code examples
djangosorl-thumbnail

I don't understand how sorl-thumbnail uses db and also a cache


I'm trying to get my head around how sorl-thumbnail works but getting a bit confused.

I know it get's a key depending on the image and its settings then saves/returns the value when it's needed. To me this seems like it would all be done with the cache. I just don't get why it's saving the key/value in a database too.

Can you explain why you need a cache engine and also a database? It doesn't make sense to me why it would need to use both.


Solution

  • Caches (in Django and in general) are generally faster to read and write but don't necessarily guarantee durability of the data stored.

    Using the database as slower but durable storage and the cache as faster storage in front is a pretty normal pattern -- heck, Django even has a session storage backend django.contrib.sessions.backends.cached_db that does just that.