Class: JSONFactory::Cache
- Inherits:
-
Object
- Object
- JSONFactory::Cache
- Includes:
- Singleton
- Defined in:
- lib/json_factory/cache.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#store ⇒ Object
Returns the value of attribute store.
Instance Method Summary collapse
- #fetch(key, options = nil, &block) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #transform_key(key) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
8 9 10 |
# File 'lib/json_factory/cache.rb', line 8 def initialize @prefix = 'json_factory' end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/json_factory/cache.rb', line 6 def prefix @prefix end |
#store ⇒ Object
Returns the value of attribute store.
6 7 8 |
# File 'lib/json_factory/cache.rb', line 6 def store @store end |
Instance Method Details
#fetch(key, options = nil, &block) ⇒ Object
16 17 18 |
# File 'lib/json_factory/cache.rb', line 16 def fetch(key, = nil, &block) store.fetch(transform_key(key), , &block) end |
#transform_key(key) ⇒ Object
12 13 14 |
# File 'lib/json_factory/cache.rb', line 12 def transform_key(key) [prefix, key].compact.join(':') end |