Revisions
-
kennyj revised this gist
Mar 2, 2012 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,11 +13,7 @@ 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 -
jugyo created this gist
Mar 2, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # 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(',')})" unless result = Rails.cache.read(key) result = __send__(:"#{method}_without_memcache_memoize", *args) Rails.cache.write(key, result, options) end result end alias_method_chain method, :memcache_memoize end end