Skip to content

Instantly share code, notes, and snippets.

@softr8
Created June 19, 2012 18:13
Show Gist options
  • Save softr8/2955680 to your computer and use it in GitHub Desktop.
Save softr8/2955680 to your computer and use it in GitHub Desktop.
Rails cache wrapper
module MyApp
# See ActiveSupport::Cache::Store for documentation.
module Cache
class << self
def fetch(key, options = {}, &block)
if block_given?
if ActionController::Base.perform_caching && options && options[:expires_in].to_i > 0
Rails.cache.fetch(key, options, &block)
else
yield
end
else
Rails.cache.read(key)
end
end
alias_method :read, :fetch
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment