Class: SpeedGun::Store::Memcache

Inherits:
Object
  • Object
show all
Defined in:
lib/speed_gun/store/memcache.rb

Constant Summary collapse

DEFAULT_PREFIX =
'speed-gun-'
DEFAULT_EXPIRES_IN_SECONDS =
60 * 60 * 24

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Memcache

Returns a new instance of Memcache.



7
8
9
10
11
# File 'lib/speed_gun/store/memcache.rb', line 7

def initialize(options = {})
  @prefix = options[:prefix] || DEFAULT_PREFIX
  @client = options[:client] || default_dalli
  @expires = options[:expires] || DEFAULT_EXPIRES_IN_SECONDS
end

Instance Method Details

#[](id) ⇒ Object



13
14
15
# File 'lib/speed_gun/store/memcache.rb', line 13

def [](id)
  @client.get("#{@prefix}#{id}")
end

#[]=(id, val) ⇒ Object



17
18
19
# File 'lib/speed_gun/store/memcache.rb', line 17

def []=(id, val)
  @client.set("#{@prefix}#{id}", val, @expires)
end