Module: Rack::Dedos::Cache::Hash

Defined in:
lib/rack/dedos/cache.rb

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/dedos/cache.rb', line 22

def get(key)
  if (value, expires_at = @store[key])
    if !expires_at || expires_at > now
      value
    else
      @store.delete(key)
      nil
    end
  end
end

#set(key, value, expires_in: @expires_in) ⇒ Object



17
18
19
20
# File 'lib/rack/dedos/cache.rb', line 17

def set(key, value, expires_in: @expires_in)
  expires_at = now + expires_in if expires_in
  @store[key] = [value, expires_at]
end