# File Ruby/lib/mini_profiler/storage/file_store.rb, line 32 def initialize(args) @path = args[:path] raise ArgumentError.new :path unless @path @timer_struct_cache = FileCache.new(@path, "mp_timers") @timer_struct_lock = Mutex.new @user_view_cache = FileCache.new(@path, "mp_views") @user_view_lock = Mutex.new me = self Thread.new do begin while true do # TODO: a sane retry count before bailing me.cleanup_cache sleep(3600) end rescue # don't crash the thread, we can clean up next time end end end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 91 def cleanup_cache files = Dir.entries(@path) @timer_struct_lock.synchronize { files.each do |f| f = @path + '/' + f File.delete f if f =~ /^mp_timers/ and (Time.now - File.mtime(f)) > EXPIRE_TIMER_CACHE end } @user_view_lock.synchronize { files.each do |f| f = @path + '/' + f File.delete f if f =~ /^mp_views/ and (Time.now - File.mtime(f)) > EXPIRE_TIMER_CACHE end } end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 85 def get_unviewed_ids(user) @user_view_lock.synchronize { @user_view_cache[user] } end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 60 def load(id) @timer_struct_lock.synchronize { @timer_struct_cache[id] } end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 54 def save(page_struct) @timer_struct_lock.synchronize { @timer_struct_cache[page_struct['Id']] = page_struct } end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 66 def set_unviewed(user, id) @user_view_lock.synchronize { current = @user_view_cache[user] current = [] unless Array === current current << id @user_view_cache[user] = current.uniq } end
# File Ruby/lib/mini_profiler/storage/file_store.rb, line 75 def set_viewed(user, id) @user_view_lock.synchronize { @user_view_cache[user] ||= [] current = @user_view_cache[user] current = [] unless Array === current current.delete(id) @user_view_cache[user] = current.uniq } end
Generated with the Darkfish Rdoc Generator 2.