Pregunta

I'm using rails and uploading images via the carrier wave plugic to AWS. I started caching the images with memcached/dalli, and it works fine for a bit...but then all images show up as broken after a while (either approx 20-30 mins or when using a different browser).

Here's an example...caching this set of images, where post.avatar_url is the AWS url for the image. Images normally load fine without caching...but caching seems to cause broken images eventually.

  <% cache ["homeimages", post] do %>
    <%= link_to image_tag(post.avatar_url), post %>
  <% end %>

What is causing the images to break?

Thank you!

¿Fue útil?

Solución

Are you uploading them as private or public? If they are private the reason why they would no longer be accessible from that url after 20-30 minutes is the permissions token on the image, which would be provided by the avatar_url method, is expiring meaning the S3 will respond with 404 file not found.

Make the images public, or try something like the following instead

<% cache(["homeimages", post], :expires_in => 20.minutes) do %>
   <%= link_to image_tag(post.avatar_url), post %>
<% end %>

The 20.minutes being what ever time the access token last. Meaning the cache will never outlast the token.

Edit

Also you do realize that your not "caching the images with memecached/dalli", but rather the img tag?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top