Last active
February 7, 2020 03:50
-
-
Save coolsoftwaretyler/1bdc269baadf6563a2df28d03cd0974b to your computer and use it in GitHub Desktop.
Rails Fragment Caching and Low Level Caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @sample_object.external_components.each do |component| %> | |
<% cache component do %> | |
<%= render component %> | |
<% end %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caching with Rails