Class: Peek::Adapters::Memcache

Inherits:
Base
  • Object
show all
Defined in:
lib/peek/adapters/memcache.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Memcache

Returns a new instance of Memcache.



7
8
9
10
# File 'lib/peek/adapters/memcache.rb', line 7

def initialize(options = {})
  @client = options.fetch(:client, ::Dalli::Client.new)
  @expires_in = options.fetch(:expires_in, 60 * 30)
end

Instance Method Details

#get(request_id) ⇒ Object



12
13
14
15
16
# File 'lib/peek/adapters/memcache.rb', line 12

def get(request_id)
  @client.get("peek:requests:#{request_id}")
rescue ::Dalli::DalliError => e
  Rails.logger.error "#{e.class.name}: #{e.message}"
end

#save(request_id) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/peek/adapters/memcache.rb', line 18

def save(request_id)
  return false if request_id.blank?

  @client.add("peek:requests:#{request_id}", Peek.results.to_json, @expires_in)
rescue ::Dalli::DalliError => e
  Rails.logger.error "#{e.class.name}: #{e.message}"
end