module Functional::Memo
Memoization is a technique for optimizing functions that are time-consuming and/or involve expensive calculations. Every time a memoized function is called the result is caches with reference to the given parameters. Subsequent calls to the function that use the same parameters will return the cached result. As a result the response time for frequently called functions is vastly increased (after the first call with any given set of) arguments, at the cost of increased memory usage (the cache).
{include:file:doc/memo.md}
@note Memoized method calls are thread safe and can safely be used in
concurrent systems. Declaring memoization on a function is *not* thread safe and should only be done during application initialization.
Public Class Methods
extended(base)
click to toggle source
@!visibility private
Calls superclass method
# File lib/functional/memo.rb, line 21 def self.extended(base) base.extend(ClassMethods) base.send(:__method_memos__=, {}) super(base) end
included(base)
click to toggle source
@!visibility private
Calls superclass method
# File lib/functional/memo.rb, line 28 def self.included(base) base.extend(ClassMethods) base.send(:__method_memos__=, {}) super(base) end