In a Rails 5.1 Dalli store (cache), S3 images are breaking after a certain amount of time

377 Views Asked by At

I've set up Dalli as a cache store and have memcached running. After a certain amount of time, I'll end up with broken S3 images (everything else still loads correctly).

Relevant lines from production.rb:

config.action_controller.perform_caching = true
config.cache_store = :dalli_store,
                   'localhost',
                   { :namespace => "PatchVault", :expires_in => 1.day, :compress => true }

The view file:

<% @issues.group_by(&:issue_type).each do |issue_type, issue| %>
<% cache issue do %>
  <h3><%= issue_type.abbreviation %>: <%= issue_type.name %></h3>
  <ul class="issue-list">
    <%= render issue %>
  </ul>
<% end -%>
<% end -%>

There is no additional caching in the _issue partial that the collection renders. but here it is for reference:

<li>
  <article class="issue">
    <% if issue.image? %>
        <%= link_to image_tag(issue.image_url(:list)),
            lodge_issue_path(issue.lodge, issue) %>
      <% else %>
        <%= link_to image_tag(
              "missing_flap.jpg",
              alt: "No Flap Image for #{issue.combined}",
              style: "width: 200px"
              ),
              lodge_issue_path(issue.lodge, issue) %>
      <% end %>
    <p class="lodge-name">
      <%= link_to issue.combined, lodge_issue_path(issue.lodge, issue) %>
      <span>(OA BBv6: <%= issue.oa_bb_combined %>)</span>
    </p>
  </article>
</li>

Initially, this will be fine and cache and run as expected. After a certain amount of time (perhaps session expiration, but it's always a few hours it seems), the S3 images start erroring out and show up as broken images. Disabling caching by commenting out the <% cache issue do %> returns the expected behavior.

Memcached is running on the server. I'm pretty sure this is a configuration issue on my part or the S3 images need to be processed differently but my Google-fu is failing me in finding a similar issue.

0

There are 0 best solutions below