lib/nanoc3/base/memoization.rb in nanoc3-3.2.0 vs lib/nanoc3/base/memoization.rb in nanoc3-3.2.1

- old
+ new

@@ -5,12 +5,10 @@ # Adds support for memoizing functions. # # @since 3.2.0 module Memoization - CACHE = {} - # Memoizes the method with the given name. The modified method will cache # the results of the original method, so that calling a method twice with # the same arguments will short-circuit and return the cached results # immediately. # @@ -48,20 +46,20 @@ alias_method original_method_name, method_name # Redefine define_method(method_name) do |*args| # Get cache - @cache ||= {} - @cache[method_name] ||= {} + @__memoization_cache ||= {} + @__memoization_cache[method_name] ||= {} # Recalculate if necessary - if !@cache[method_name].has_key?(args) + if !@__memoization_cache[method_name].has_key?(args) result = send(original_method_name, *args) - @cache[method_name][args] = result + @__memoization_cache[method_name][args] = result end # Done - @cache[method_name][args] + @__memoization_cache[method_name][args] end end end