Class: FCC::Station::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/fcc/station/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



11
12
13
14
15
# File 'lib/fcc/station/cache.rb', line 11

def initialize
  @lightly = Lightly.new(life: '3d', hash: true).tap do |cache|
    cache.prune
  end
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



9
10
11
# File 'lib/fcc/station/cache.rb', line 9

def store
  @store
end

Instance Method Details

#fetch(key) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fcc/station/cache.rb', line 21

def fetch(key)
  FCC.log("Retreiving #{key} from cache")
  @lightly.get(key.to_s) do
    FCC.log "Loading up the cache with results for key: #{key}. This might take a minuteā€¦"
    value = yield
    if value
      value
    else
      nil
    end
  end
end

#flushObject



17
18
19
# File 'lib/fcc/station/cache.rb', line 17

def flush
  @lightly.flush
end