Class: Volatile::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/volatile_wtf/manager.rb

Overview

Manages the server side of Volatile storage, handles API requests

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



7
8
9
# File 'lib/volatile_wtf/manager.rb', line 7

def initialize
  @cache = Cache.new
end

Instance Method Details

#created(key) ⇒ Object



25
26
27
28
# File 'lib/volatile_wtf/manager.rb', line 25

def created(key)
  time = key_modificator key, :created
  Time.at(time.to_i)
end

#modified(key) ⇒ Object



30
31
32
33
# File 'lib/volatile_wtf/manager.rb', line 30

def modified(key)
  time = key_modificator key, :modified
  Time.at(time.to_i)
end

#reload(key) ⇒ Object



20
21
22
23
# File 'lib/volatile_wtf/manager.rb', line 20

def reload(key)
  fresh_value = get_from api_uri key
  store(key, fresh_value)
end

#retrieve(key) ⇒ Object



16
17
18
# File 'lib/volatile_wtf/manager.rb', line 16

def retrieve(key)
  @cache.fetch(key) { get_from api_uri key }
end

#store(key, value) ⇒ Object



11
12
13
14
# File 'lib/volatile_wtf/manager.rb', line 11

def store(key, value)
  get_from api_uri key, value
  @cache.save(key, value)
end