# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 7 def initialize(args = nil) args ||= {} @expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS @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
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 57 def cleanup_cache expire_older_than = ((Time.now.to_f - @expires_in_seconds) * 1000).to_i @timer_struct_lock.synchronize { @timer_struct_cache.delete_if { |k, v| v['Started'] < expire_older_than } } end
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 51 def get_unviewed_ids(user) @user_view_lock.synchronize { @user_view_cache[user] } end
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 31 def load(id) @timer_struct_lock.synchronize { @timer_struct_cache[id] } end
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 25 def save(page_struct) @timer_struct_lock.synchronize { @timer_struct_cache[page_struct['Id']] = page_struct } end
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 37 def set_unviewed(user, id) @user_view_lock.synchronize { @user_view_cache[user] ||= [] @user_view_cache[user] << id } end
# File Ruby/lib/mini_profiler/storage/memory_store.rb, line 44 def set_viewed(user, id) @user_view_lock.synchronize { @user_view_cache[user] ||= [] @user_view_cache[user].delete(id) } end