Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kineticac/399161 to your computer and use it in GitHub Desktop.
Save kineticac/399161 to your computer and use it in GitHub Desktop.
# application_controller.rb
def cache_fetch(key, time_expire = 0)
if ENV["RAILS_ENV"] == 'development' && !CACHE_DEVELOPMENT
yield
else
# CACHE.fetch(key, time_expire){yield} #this is the old way
unless output = CACHE.get(key)
output = yield
CACHE.set(key, output, time_expire)
end
return output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment