django-imagekit
django-imagekit copied to clipboard
Feature Request: Add "Safe" caching strategy
I think it would be useful to have a third caching strategy that is a combination of Optimistic and JustInTime. Optimistic increases performance by pre-generating the images, while also allowing for a fall-back if the image is not generated.
class Safe(object): """ A combination of optimistic and just in time """ def on_source_saved(self, file): file.generate() def on_existence_required(self, file): file.generate() def on_content_required(self, file): file.generate()
@ninapavlich Sounds good to me. I'm not too crazy about the name "Safe" though…JIT is just as safe. Can we think of something less scary?
Oh sure, what about Redundant? :)
But let me describe my use-case in case this doesn't make sense. I have a large library of images (> 10000 images) that were imported using the JustInTime setting.
Our media picker is paginated to show 50 images at a time along with each of its six image variants. Loading each new page using JustInTime takes several minutes per page. If I switch to Optimistic, then newly uploaded images would be generated, but the old images wouldn't.
Would it make sense in this case to use a combination of optimistic and just in time?
Yeah, that makes sense. You'll still have the overhead of guaranteeing the file's existence on access (but caching elimates that). Your use case is basically the reason that strategies exist. Have you been using your strategy class?