Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created June 25, 2014 20:29
Show Gist options
  • Save DriesS/c543581c40f2d9caa40e to your computer and use it in GitHub Desktop.
Save DriesS/c543581c40f2d9caa40e to your computer and use it in GitHub Desktop.
def top_menu_cache_key
rounded_time = Time.zone.now.round(30.minutes)
if Rails.cache.fetch('top_menu_cache_key').nil? || rounded_time != Rails.cache.fetch("rounded_time")
debugger
Rails.cache.write('top_menu_cache_key', "top_menu:#{Product.active.on_sale.maximum(:updated_at)}")
Rails.cache.write('rounded_time', rounded_time)
end
return Rails.cache.fetch('top_menu_cache_key')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment