jemnotesversion 2 / featuring this entry or see all/search

Apr 8
It’s easy to set up memory caching in rails. This page has some details. The only steps from it that I required were
# Inside config/environment.rb:
require 'memcache'
CACHE = MemCache.new '127.0.0.1'

# A helper method:
def data_cache key
  unless output = CACHE.get(key)
    output = yield
    CACHE.set key, output, 1.hour
  end
  output
end

# When using it:
data_cache 'tag' do
  thing_to_cache
end