Skip to content

Instantly share code, notes, and snippets.

@coolsoftwaretyler
Last active February 7, 2020 03:50
Show Gist options
  • Save coolsoftwaretyler/1bdc269baadf6563a2df28d03cd0974b to your computer and use it in GitHub Desktop.
Save coolsoftwaretyler/1bdc269baadf6563a2df28d03cd0974b to your computer and use it in GitHub Desktop.
Rails Fragment Caching and Low Level Caching
class SampleObject < ApplicationRecord
def external_components
Rails.cache.fetch("#{cache_key_with_version}/components", expires_in: 12.hours) do
# Some long running task that fetches "components"
end
end
end
<% @sample_object.external_components.each do |component| %>
<% cache component do %>
<%= render component %>
<% end %>
<% end %>
@coolsoftwaretyler
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment