Class: Rack::MiniProfiler::FileStore

Inherits:
AbstractStore show all
Defined in:
lib/mini_profiler/storage/file_store.rb

Defined Under Namespace

Classes: FileCache

Constant Summary collapse

EXPIRE_TIMER_CACHE =
3600 * 24

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ FileStore

Returns a new instance of FileStore.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File '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
    while true do
      me.cleanup_cache if MiniProfiler.instance
      sleep(3600)
    end
  end
end

Instance Method Details

#get_unviewed_ids(user) ⇒ Object



80
81
82
83
84
# File 'lib/mini_profiler/storage/file_store.rb', line 80

def get_unviewed_ids(user)
  @user_view_lock.synchronize {
    @user_view_cache[user]
  }
end

#load(id) ⇒ Object



55
56
57
58
59
# File 'lib/mini_profiler/storage/file_store.rb', line 55

def load(id)
			  @timer_struct_lock.synchronize {
    @timer_struct_cache[id]
  }
end

#save(page_struct) ⇒ Object



49
50
51
52
53
# File 'lib/mini_profiler/storage/file_store.rb', line 49

def save(page_struct)
		  	@timer_struct_lock.synchronize {
@timer_struct_cache[page_struct['Id']] = page_struct
			  }
end

#set_unviewed(user, id) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/mini_profiler/storage/file_store.rb', line 61

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

#set_viewed(user, id) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/mini_profiler/storage/file_store.rb', line 70

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