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)
-
- (Object) get(key)
Retrieve the value for a key, expiring the cache and/or loading it if necessary.
-
- (Store) initialize(finder, config)
constructor
A new instance of Store.
-
- (Array<String>) keys
The list of currently loaded keys.
-
- (Integer) size
The current size of the cache.
Constructor Details
- (Store) initialize(finder, config)
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
- (Object) get(key)
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 |
- (Array<String>) keys
The list of currently loaded keys
25 26 27 |
# File 'lib/figgy/store.rb', line 25 def keys @cache.keys end |
- (Integer) size
The current size of the cache
30 31 32 |
# File 'lib/figgy/store.rb', line 30 def size @cache.size end |