Class: Figgy::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/figgy/store.rb

Overview

The backing object for a Figgy instance.

Instance Method Summary collapse

Constructor Details

#initialize(finder, config) ⇒ 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.

Raises:



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

#keysArray<String>



25
26
27
# File 'lib/figgy/store.rb', line 25

def keys
  @cache.keys
end

#sizeInteger



30
31
32
# File 'lib/figgy/store.rb', line 30

def size
  @cache.size
end