Class: Perforated::Cache
- Inherits:
-
Object
- Object
- Perforated::Cache
- Defined in:
- lib/perforated/cache.rb
Instance Attribute Summary collapse
-
#enumerable ⇒ Object
Returns the value of attribute enumerable.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#initialize(enumerable, strategy = Perforated::Strategy) ⇒ Cache
constructor
A new instance of Cache.
- #to_json(rooted: false, batch_size: 1000, &block) ⇒ Object
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
#enumerable ⇒ Object
Returns the value of attribute enumerable.
7 8 9 |
# File 'lib/perforated/cache.rb', line 7 def enumerable @enumerable end |
#strategy ⇒ Object
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, batch_size: 1000, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/perforated/cache.rb', line 14 def to_json(rooted: false, batch_size: 1000, &block) results = [] enumerable.each_slice(batch_size) do |subset| keyed = key_mapped(subset) results << fetch_multi(keyed) do |key| if block_given? (yield keyed[key]).to_json else keyed[key].to_json end end.values end Perforated::Rebuilder.new(results).rebuild(rooted: rooted) end |