Skip to content

Instantly share code, notes, and snippets.

@HansHauge
Created March 19, 2015 15:02
Show Gist options
  • Save HansHauge/30aa21a22aa0c0f5db32 to your computer and use it in GitHub Desktop.
Save HansHauge/30aa21a22aa0c0f5db32 to your computer and use it in GitHub Desktop.
Rails Fragment Caching @ Controller
# in your controller
time_range = (DateTime.now - 1.day)..DateTime.now
@listings = Rails.cache.fetch('front-page', expires_in: 1.hour) do
Listing.where(created_at: time_range)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment