django-imagekit icon indicating copy to clipboard operation
django-imagekit copied to clipboard

Feature Request: Add "Safe" caching strategy

Open ninapavlich opened this issue 11 years ago • 3 comments

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 avatar May 09 '14 15:05 ninapavlich

@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?

matthewwithanm avatar May 09 '14 21:05 matthewwithanm

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?

ninapavlich avatar May 12 '14 18:05 ninapavlich

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?

matthewwithanm avatar May 20 '14 13:05 matthewwithanm