Module: Miasma::Utils::Memoization
- Included in:
- Models::Orchestration::Stack, Types::Api, Types::Collection, Types::Model
- Defined in:
- lib/miasma/utils/memoization.rb
Overview
Memoization helpers
Instance Method Summary (collapse)
- - (Object) _memo
-
- (TrueClass) clear_memoizations!
Remove all memoized values.
-
- (Object) memoize(key, direct = false) { ... }
Memoize data.
-
- (NilClass) unmemoize(key, direct = false)
Remove memoized value.
Instance Method Details
- (Object) _memo
25 26 27 |
# File 'lib/miasma/utils/memoization.rb', line 25 def _memo Thread.current[:miasma_memoization] ||= Smash.new end |
- (TrueClass) clear_memoizations!
Remove all memoized values
44 45 46 47 48 49 50 51 |
# File 'lib/miasma/utils/memoization.rb', line 44 def clear_memoizations! _memo.keys.find_all do |key| key.to_s.start_with?("#{self.object_id}_") end.each do |key| _memo.delete(key) end true end |
- (Object) memoize(key, direct = false) { ... }
Memoize data
15 16 17 18 19 20 21 22 23 |
# File 'lib/miasma/utils/memoization.rb', line 15 def memoize(key, direct=false) unless(direct) key = "#{self.object_id}_#{key}" end unless(_memo.has_key?(key)) _memo[key] = yield end _memo[key] end |
- (NilClass) unmemoize(key, direct = false)
Remove memoized value
34 35 36 37 38 39 |
# File 'lib/miasma/utils/memoization.rb', line 34 def unmemoize(key, direct=false) unless(direct) key = "#{self.object_id}_#{key}" end _memo.delete(key) end |