Class: McCache

Inherits:
Object
  • Object
show all
Defined in:
lib/caches/mc_cache.rb

Class Method Summary collapse

Class Method Details

.clientObject



5
6
7
# File 'lib/caches/mc_cache.rb', line 5

def client
  @@client
end

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



27
28
29
30
31
# File 'lib/caches/mc_cache.rb', line 27

def delete(key, options = {})
  deleted = read(key)
  client.delete(key)
  deleted
end

.initializeObject



9
10
11
12
13
14
15
# File 'lib/caches/mc_cache.rb', line 9

def initialize
  config = ConfigService.load_config('memcached.yml')[ConfigService.environment]
  @@client ||= Dalli::Client.new(config['host'], config)
rescue => error
  SdkLogger.logger.error("McCache.initialize error: #{error.message}")
  @@client = nil
end

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

Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html



19
20
21
# File 'lib/caches/mc_cache.rb', line 19

def read(key, options = {})
  client.get(key, options)
end

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



23
24
25
# File 'lib/caches/mc_cache.rb', line 23

def write(key, value, options = {})
  client.set(key, value, options[:expires_in], options)
end