Class: Rack::MiniProfiler::FileStore::FileCache

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

Instance Method Summary collapse

Constructor Details

#initialize(path, prefix) ⇒ FileCache

Returns a new instance of FileCache.



12
13
14
15
# File 'lib/mini_profiler/storage/file_store.rb', line 12

def initialize(path, prefix)
  @path = path
  @prefix = prefix
end

Instance Method Details

#[](key) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/mini_profiler/storage/file_store.rb', line 17

def [](key)
  begin
    data = ::File.open(path(key), "rb") { |f| f.read }
    Marshal.load data
  rescue
    nil
  end
end

#[]=(key, val) ⇒ Object



26
27
28
29
30
31
# File 'lib/mini_profiler/storage/file_store.rb', line 26

def []=(key, val)
  ::File.open(path(key), "wb+") do |f|
    f.sync = true
    f.write Marshal.dump(val)
  end
end