Class: ECB::Exchange::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/ecb/exchange/cache.rb

Constant Summary collapse

KEY_PREFIX =
"ecb_exchange_rates_for_date".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backendObject

Returns the value of attribute backend.



9
10
11
# File 'lib/ecb/exchange/cache.rb', line 9

def backend
  @backend
end

Class Method Details

.read(key) ⇒ Object



16
17
18
# File 'lib/ecb/exchange/cache.rb', line 16

def self.read(key)
  store.read(cache_key(key))
end

.storeObject

use backend if set (must respond to read, write), otherwise Rails.cache will be used (if available) or we fall back to use an in-memory cache



22
23
24
25
26
27
28
29
30
# File 'lib/ecb/exchange/cache.rb', line 22

def self.store
  if backend
    backend
  elsif defined?(Rails) && Rails.cache
    Rails.cache
  else
    MemoryCache.cache
  end
end

.write(key, value) ⇒ Object



12
13
14
# File 'lib/ecb/exchange/cache.rb', line 12

def self.write(key, value)
  store.write(cache_key(key), value)
end