Class: Rack::MiniProfiler::MemcacheStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- Rack::MiniProfiler::MemcacheStore
- Defined in:
- lib/mini_profiler/storage/memcache_store.rb
Constant Summary collapse
- EXPIRES_IN_SECONDS =
60 * 60 * 24
- MAX_RETRIES =
10
Instance Method Summary collapse
- #get_unviewed_ids(user) ⇒ Object
-
#initialize(args = nil) ⇒ MemcacheStore
constructor
A new instance of MemcacheStore.
- #load(id) ⇒ Object
- #save(page_struct) ⇒ Object
- #set_unviewed(user, id) ⇒ Object
- #set_viewed(user, id) ⇒ Object
Methods inherited from AbstractStore
Constructor Details
#initialize(args = nil) ⇒ MemcacheStore
Returns a new instance of MemcacheStore.
8 9 10 11 12 13 14 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 8 def initialize(args = nil) require 'dalli' unless defined? Dalli args ||= {} @prefix = args[:prefix] || "MPMemcacheStore" @client = args[:client] || Dalli::Client.new @expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS end |
Instance Method Details
#get_unviewed_ids(user) ⇒ Object
45 46 47 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 45 def get_unviewed_ids(user) @client.get("#{@prefix}-#{user}-v") || [] end |
#load(id) ⇒ Object
20 21 22 23 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 20 def load(id) raw = @client.get("#{@prefix}#{id}") Marshal::load(raw) if raw end |
#save(page_struct) ⇒ Object
16 17 18 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 16 def save(page_struct) @client.set("#{@prefix}#{page_struct[:id]}", Marshal::dump(page_struct), @expires_in_seconds) end |
#set_unviewed(user, id) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 25 def set_unviewed(user, id) @client.add("#{@prefix}-#{user}-v", [], @expires_in_seconds) MAX_RETRIES.times do break if @client.cas("#{@prefix}-#{user}-v", @expires_in_seconds) do |ids| ids << id unless ids.include?(id) ids end end end |
#set_viewed(user, id) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/mini_profiler/storage/memcache_store.rb', line 35 def set_viewed(user, id) @client.add("#{@prefix}-#{user}-v", [], @expires_in_seconds) MAX_RETRIES.times do break if @client.cas("#{@prefix}-#{user}-v", @expires_in_seconds) do |ids| ids.delete id ids end end end |