public
Created — forked from jugyo/memcache_memoize.rb

memoize with memcache store in Rails

  • Download Gist
memcache_memoize.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# Usage:
#
# module ApplicationHelper
# extend MemcacheMemoize
#
# def bar(count = 10)
# "BAR" * count
# end
# memcache_memoize :bar, :expires_in => 10
# end
#
module MemcacheMemoize
def memcache_memoize(method, options)
define_method(:"#{method}_with_memcache_memoize") do |*args|
key = "#{self.class.name}##{method}(#{args.map(&:to_s).join(',')})"
Rails.cache.fetch(key) { __send__(:"#{method}_without_memcache_memoize", *args) }
end
alias_method_chain method, :memcache_memoize
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.