Class: Rack::MiniProfiler::MemoryStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- Rack::MiniProfiler::MemoryStore
- Defined in:
- lib/mini_profiler/storage/memory_store.rb
Constant Summary collapse
- EXPIRE_TIMER_CACHE =
3600 * 24
Instance Method Summary collapse
- #get_unviewed_ids(user) ⇒ Object
-
#initialize(args) ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #load(id) ⇒ Object
- #save(page_struct) ⇒ Object
- #set_unviewed(user, id) ⇒ Object
- #set_viewed(user, id) ⇒ Object
Constructor Details
#initialize(args) ⇒ MemoryStore
Returns a new instance of MemoryStore.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File '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 |
Instance Method Details
#get_unviewed_ids(user) ⇒ Object
49 50 51 52 53 |
# File '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) ⇒ Object
29 30 31 32 33 |
# File 'lib/mini_profiler/storage/memory_store.rb', line 29 def load(id) @timer_struct_lock.synchronize { @timer_struct_cache[id] } end |
#save(page_struct) ⇒ Object
23 24 25 26 27 |
# File '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) ⇒ Object
35 36 37 38 39 40 |
# File '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) ⇒ Object
42 43 44 45 46 47 |
# File '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 |