module Caching::ClassMethods

Public Instance Methods

cache_method(method) click to toggle source
# File lib/caching.rb, line 10
def cache_method(method)
  alias_method "#{method}_without_cache", method

  define_method method do |*args, &block|
    args_key = args.any? ? "_#{Base64.encode64(Marshal.dump(args))}" : ''
    method_key = "#{method}#{args_key}"
    cached_methods_keys[method] << method_key
    cache_storage.fetch(method_key) { send "#{method}_without_cache", *args, &block }
  end
end