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, &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, &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 |