[Answer]-Check if sorl thumbnail has already cached an image using the low level API

1👍

In my version sorl.thumbnail, 11.12, the method get_thumbnail is defined in sorl.thumbnail.base.py and starts as follows:

def get_thumbnail(self, file_, geometry_string, **options):
    """..."""
    source = ImageFile(file_)
    for key, value in self.default_options.iteritems():
        options.setdefault(key, value)
    # ...
    for key, attr in self.extra_options:
        value = getattr(settings, attr)
        if value != getattr(default_settings, attr):
            options.setdefault(key, value)
    name = self._get_thumbnail_filename(source, geometry_string, options)
    thumbnail = ImageFile(name, default.storage)
    cached = default.kvstore.get(thumbnail)
    if cached:
        return cached
    if not thumbnail.exists():
        ...

If you use this code and return something like

cached or thumbnail.exists()

this should give you the desired result.

Leave a comment