lib/mini_profiler/storage/memory_store.rb in rack-mini-profiler-0.9.9.2 vs lib/mini_profiler/storage/memory_store.rb in rack-mini-profiler-0.10.1

- old
+ new

@@ -47,15 +47,19 @@ CLEANUP_CYCLE = 3600 def initialize(args = nil) args ||= {} @expires_in_seconds = args.fetch(:expires_in) { EXPIRES_IN_SECONDS } + + @token1, @token2, @cycle_tokens_at = nil + initialize_locks initialize_cleanup_thread(args) end def initialize_locks + @token_lock = Mutex.new @timer_struct_lock = Mutex.new @user_view_lock = Mutex.new @timer_struct_cache = {} @user_view_cache = {} end @@ -96,10 +100,16 @@ @user_view_cache[user] ||= [] @user_view_cache[user].delete(id) } end + def set_all_unviewed(user, ids) + @user_view_lock.synchronize { + @user_view_cache[user] = ids + } + end + def get_unviewed_ids(user) @user_view_lock.synchronize { @user_view_cache[user] } end @@ -107,9 +117,23 @@ 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 + + def allowed_tokens + @token_lock.synchronize do + + unless @cycle_at && (@cycle_at > Time.now) + @token2 = @token1 + @token1 = SecureRandom.hex + @cycle_at = Time.now + Rack::MiniProfiler::AbstractStore::MAX_TOKEN_AGE + end + + [@token1, @token2].compact + + end end end end end