def method_for_cached(object, key, fetch_method=:fetch, method_name=nil)
      method_name = ("cached_" + (method_name || key)).gsub(/[^\w\!\?]/, '_')
      method_body = <<-END
        def #{method_name}(*args, &block)
          opts = args.empty? ? {} : args.first

          proxy = AridCache::CacheProxy.new(self, #{key.inspect}, opts, &block)
          if opts[:clear] == true
            proxy.clear_cached
          else
            proxy.#{fetch_method.to_s}
          end
        end
      END
      # Get the correct object
      object = (class << object; self; end) if object.is_a?(Class)
      object.class_eval(method_body, __FILE__, __LINE__)
    end
def method_for_cached(object, key, fetch_method=:fetch, method_name=nil)
      method_name = ("cached_" + (method_name || key)).gsub(/[^\w\!\?]/, '_')
      method_body = <<-END
        def #{method_name}(*args, &block)
          opts = args.empty? ? {} : args.first

          proxy = AridCache::CacheProxy.new(self, #{key.inspect}, opts, &block)
          if opts[:clear] == true
            proxy.clear_cached
          else
            proxy.#{fetch_method.to_s}
          end
        end
      END
      # Get the correct object
      object = (class << object; self; end) if object.is_a?(Class)
      object.class_eval(method_body, __FILE__, __LINE__)
    end
Dynamically define a method on the object's class to return cached results