Class: Memcached

Inherits:
Object
  • Object
show all
Defined in:
lib/time_bandits/monkey_patches/memcached.rb

Instance Method Summary collapse

Instance Method Details

#get_with_benchmark(key, marshal = true) ⇒ Object Also known as: get



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/time_bandits/monkey_patches/memcached.rb', line 9

def get_with_benchmark(key, marshal = true)
  ActiveSupport::Notifications.instrument("get.memcached") do |payload|
    if key.is_a?(Array)
      payload[:reads] = (num_keys = key.size)
      results = []
      begin
        results = get_without_benchmark(key, marshal)
      rescue Memcached::NotFound
      end
      payload[:misses] = num_keys - results.size
      results
    else
      val = nil
      payload[:reads] = 1
      begin
        val = get_without_benchmark(key, marshal)
      rescue Memcached::NotFound
      end
      payload[:misses] = val.nil? ? 1 : 0
      val
    end
  end
end

#set_with_benchmark(*args) ⇒ Object Also known as: set



35
36
37
38
39
# File 'lib/time_bandits/monkey_patches/memcached.rb', line 35

def set_with_benchmark(*args)
  ActiveSupport::Notifications.instrument("set.memcached") do
    set_without_benchmark(*args)
  end
end