Sha256: 326c8b55ab09ba58d60e298c53a95eca7c19bf4430974d53b180c7f7e825dfd9

Contents?: true

Size: 576 Bytes

Versions: 4

Compression:

Stored size: 576 Bytes

Contents

require 'speed_gun/store/base'

class SpeedGun::Store::Memcache
  DEFAULT_PREFIX = 'speed-gun-'
  DEFAULT_EXPIRES_IN_SECONDS = 60 * 60 * 24

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

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

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

  private

  def default_dalli
    require 'dalli' unless defined?(Dalli)
    Dalli::Client.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
speed_gun-0.0.4 lib/speed_gun/store/memcache.rb
speed_gun-0.0.3 lib/speed_gun/store/memcache.rb
speed_gun-0.0.2 lib/speed_gun/store/memcache.rb
speed_gun-0.0.1 lib/speed_gun/store/memcache.rb