delayed_paperclip icon indicating copy to clipboard operation
delayed_paperclip copied to clipboard

Regenerate a cache after processing of an image

Open alexcp opened this issue 12 years ago • 7 comments

I couldn't find a good way to regenerate a cache when an image as been process.

What I wanted to do seems quite simple, I wanted to show the original image while it is being process in the background.

But the problem is that when the image is resized, the original keep showing up in the cache.

I wrote this hack to do it, but it's really ugly, I am sure we can find a better way to do it.

alexcp avatar Feb 21 '13 15:02 alexcp

So what you're looking for is an after_processing callback to bust the cache. Delayed_paperclip should observe paperclip's callback after_post_process. Let me know if your expiring fragment doesn't work there.

ScotterC avatar Jul 19 '13 20:07 ScotterC

Are you still experiencing this issue?

jrgifford avatar Oct 22 '13 16:10 jrgifford

I also ran into this issue. Maybe the split processing might be related, but I doubt it? The callback fires when the images are done (not delayed), even if I set the callback to on the video attribute specifically (after_video_post_process).

mikaelprag avatar Dec 06 '13 12:12 mikaelprag

I had this same issue and was able to figure out a relatively happy solution.

For me there was no need to monkeypatch the delayed_paperclip DelayedJob ... I created an ActiveRecord concern called 'has_delayed_paperclip' and setup an 'after_post_process' callback hook in there to invoke a 'clear_cache' method.

Here's a gist I created with the concern: https://gist.github.com/kevinmtrowbridge/ca3435054d22eb2d2ac1

Once you've stuck that in the models/concerns directory, you can setup delayed_paperclip within models using your wrapper method like:

custom_process_in_background :image

kevinmtrowbridge avatar May 08 '14 02:05 kevinmtrowbridge

@alexcp @kevinmtrowbridge , I am also trying to display the original image while processing. Can you give me some hints as to how did you go about it? Where do you get the path to the original file? Are you using @queued_for_write from paperclip? I tried passing a symbol with the name of the method to :processing_image_url, so that it would dynamically choose the path for the image to display for each model. But at the time this method is called, @queued_for_write is empty, leaving me unable to set the path to the original for the time of processing.

kamelury avatar Jul 24 '14 13:07 kamelury

I'm pretty sure the original filename is just there via image_tag model.paperclip_image while processing. The original gets copied into place immediately and is available immediately.

The styles, the images of different sizes or coloring options, that paperclip creates, those are not available while processing. Please see this section of the documentation for more information about that.

This thread is about clearing a cache or carrying out some other action, after the processing has finished. Do you need to do something like that?

kevinmtrowbridge avatar Jul 24 '14 15:07 kevinmtrowbridge

@kevinmtrowbridge , thank for your answer! I was hoping it can be done not in the view. I created a new issue where I explain what I would like to achieve: https://github.com/jrgifford/delayed_paperclip/issues/99.

kamelury avatar Jul 29 '14 16:07 kamelury