Class: Figgy::Store
- Inherits:
-
Object
- Object
- Figgy::Store
- Defined in:
- lib/figgy/store.rb
Overview
The backing object for a Figgy instance.
Instance Method Summary collapse
-
#get(key) ⇒ Object
Retrieve the value for a key, expiring the cache and/or loading it if necessary.
-
#initialize(finder, config) ⇒ Store
constructor
A new instance of Store.
-
#keys ⇒ Array<String>
The list of currently loaded keys.
-
#size ⇒ Integer
The current size of the cache.
Constructor Details
#initialize(finder, config) ⇒ Store
Returns a new instance of Store.
4 5 6 7 8 |
# File 'lib/figgy/store.rb', line 4 def initialize(finder, config) @finder = finder @config = config @cache = {} end |
Instance Method Details
#get(key) ⇒ Object
Retrieve the value for a key, expiring the cache and/or loading it if necessary.
14 15 16 17 18 19 20 21 22 |
# File 'lib/figgy/store.rb', line 14 def get(key) key = key.to_s @cache.delete(key) if @config.always_reload? if @cache.key?(key) @cache[key] else @cache[key] = @finder.load(key) end end |
#keys ⇒ Array<String>
Returns the list of currently loaded keys.
25 26 27 |
# File 'lib/figgy/store.rb', line 25 def keys @cache.keys end |
#size ⇒ Integer
Returns the current size of the cache.
30 31 32 |
# File 'lib/figgy/store.rb', line 30 def size @cache.size end |