Skip to content

Instantly share code, notes, and snippets.

@kineticac
Created May 12, 2010 21:19
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/399136 to your computer and use it in GitHub Desktop.
Save kineticac/399136 to your computer and use it in GitHub Desktop.
# development.rb
# require 'memcache'
# CACHE = Memcached::Rails.new '127.0.0.1:11211'
# config.cache_store = :mem_cache_store, Memcached::Rails.new
# CACHE_DEVELOPMENT = true
# config.action_controller.perform_caching = true
# config.cache_classes = true
CACHE_DEVELOPMENT = false
config.action_controller.perform_caching = false
config.cache_classes = false
# application_controller.rb
def cache_fetch(key, time_expire = 0)
if ENV["RAILS_ENV"] == 'development' && !CACHE_DEVELOPMENT
yield
else
unless output = CACHE.get(key)
output = yield
CACHE.set(key, output, time_expire)
end
return output
end
end
# users_controller.rb
@teams = cache_fetch("teams"){
Team.find(:all)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment