Parent

Files

Rack::MiniProfiler::MemoryStore

Constants

EXPIRE_TIMER_CACHE

Public Class Methods

new(args) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 7
def initialize(args)
  @timer_struct_lock = Mutex.new
  @timer_struct_cache = {}
  @user_view_lock = Mutex.new
  @user_view_cache = {}

  # TODO: fix it to use weak ref, trouble is may be broken in 1.9 so need to use the 'ref' gem

  me = self
  Thread.new do
    while true do
      me.cleanup_cache
      sleep(3600)
    end
  end
end

Public Instance Methods

cleanup_cache() click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 55
def cleanup_cache
  expire_older_than = ((Time.now.to_f - MiniProfiler::MemoryStore::EXPIRE_TIMER_CACHE) * 1000).to_i
  @timer_struct_lock.synchronize {
    @timer_struct_cache.delete_if { |k, v| v['Started'] < expire_older_than }
  }
end
get_unviewed_ids(user) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 49
def get_unviewed_ids(user)
  @user_view_lock.synchronize {
    @user_view_cache[user]
  }
end
load(id) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 29
def load(id)
                    @timer_struct_lock.synchronize {
    @timer_struct_cache[id]
  }
end
save(page_struct) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 23
def save(page_struct)
                @timer_struct_lock.synchronize {
                       @timer_struct_cache[page_struct['Id']] = page_struct
                    }
end
set_unviewed(user, id) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 35
def set_unviewed(user, id)
  @user_view_lock.synchronize {
    @user_view_cache[user] ||= []
    @user_view_cache[user] << id
  }
end
set_viewed(user, id) click to toggle source
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 42
def set_viewed(user, id)
  @user_view_lock.synchronize {
    @user_view_cache[user] ||= []
    @user_view_cache[user].delete(id)
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.