Class: CacheService

Inherits:
Object
  • Object
show all
Defined in:
lib/services/cache_service.rb

Class Method Summary collapse

Class Method Details

.cacheObject



6
7
8
# File 'lib/services/cache_service.rb', line 6

def cache
  @@cache
end

.cache=(other_cache) ⇒ Object



10
11
12
# File 'lib/services/cache_service.rb', line 10

def cache=(other_cache)
  @@cache = other_cache
end

.delete(key, options = {}) ⇒ Object



35
36
37
38
# File 'lib/services/cache_service.rb', line 35

def delete(key, options = {})
  return nil unless cache
  cache.delete(key, options)
end

.initializeObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/services/cache_service.rb', line 14

def initialize
  config = ConfigService.load_config('cache_config.yml')[ConfigService.environment]
  # Load all the existing caches in the system, outside of the gem
  Dir.glob("#{File.expand_path('.')}/caches/*.rb").each { |rb_file| require rb_file }
  @@cache ||= eval(config['cache'])
  SdkLogger.logger = eval(config['logger']) if config['logger'].present?
rescue Exception => error
  puts("Error #{error.message}")
  @@cache = nil
end

.read(key, options = {}) ⇒ Object



25
26
27
28
# File 'lib/services/cache_service.rb', line 25

def read(key, options = {})
  return nil unless cache
  cache.read(key, options)
end

.write(key, value, options = {}) ⇒ Object



30
31
32
33
# File 'lib/services/cache_service.rb', line 30

def write(key, value, options = {})
  return nil unless cache
  cache.write(key, value, options)
end