Class: Perforated::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/perforated/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enumerable, strategy = Perforated::Strategy) ⇒ Cache

Returns a new instance of Cache.



9
10
11
12
# File 'lib/perforated/cache.rb', line 9

def initialize(enumerable, strategy = Perforated::Strategy)
  @enumerable = enumerable
  @strategy   = strategy
end

Instance Attribute Details

#enumerableObject

Returns the value of attribute enumerable.



7
8
9
# File 'lib/perforated/cache.rb', line 7

def enumerable
  @enumerable
end

#strategyObject

Returns the value of attribute strategy.



7
8
9
# File 'lib/perforated/cache.rb', line 7

def strategy
  @strategy
end

Instance Method Details

#to_json(rooted: false, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/perforated/cache.rb', line 14

def to_json(rooted: false, &block)
  keyed   = key_mapped(enumerable, &block)
  results = fetch_multi(keyed) { |key| keyed[key].to_json }.values

  rebuild(results, rooted)
end