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


7
8
9
# File 'lib/ecb/exchange/cache.rb', line 7

def backend
  @backend
end

Class Method Details

.read(key) ⇒ Object


14
15
16
# File 'lib/ecb/exchange/cache.rb', line 14

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


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

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

.write(key, value) ⇒ Object


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

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