Skip to content

Instantly share code, notes, and snippets.

@cawel
Forked from macournoyer/snippet.rb
Created February 18, 2009 19:09
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 cawel/66481 to your computer and use it in GitHub Desktop.
Save cawel/66481 to your computer and use it in GitHub Desktop.
def self.memoize_with_memcache(name)
define_method "#{name}_with_memo" do
key = [self.class.name, id.to_s] * '/'
Cache.get(key) || Cache.put(key, name_without_memo)
end
alias_method_chain name.to_sym, :memo #needs :to_sym here, otherwise 'name' is unrecognized
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment