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.



14
15
16
17
# File 'lib/mini_profiler/storage/file_store.rb', line 14

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

Instance Method Details

#[](key) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/mini_profiler/storage/file_store.rb', line 19

def [](key)
  begin
    data = ::File.open(path(key), "rb") { |f| f.read }
    # rubocop:disable Security/MarshalLoad
    Marshal.load data
    # rubocop:enable Security/MarshalLoad
  rescue
    nil
  end
end

#[]=(key, val) ⇒ Object



30
31
32
33
34
35
# File 'lib/mini_profiler/storage/file_store.rb', line 30

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