Module: Functional::Memo
- Defined in:
- lib/functional/memo.rb
Overview
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.
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 incresed (after the first call with any given set of) arguments, at the cost of increased memory usage (the cache).
Class Method Summary collapse
Class Method Details
.extended(base) ⇒ Object
20 21 22 23 24 |
# File 'lib/functional/memo.rb', line 20 def self.extended(base) base.extend(ClassMethods) base.send(:__method_memos__=, {}) super(base) end |
.included(base) ⇒ Object
26 27 28 29 30 |
# File 'lib/functional/memo.rb', line 26 def self.included(base) base.extend(ClassMethods) base.send(:__method_memos__=, {}) super(base) end |