Class: Rack::MiniProfiler::FileStore::FileCache
- Inherits:
-
Object
- Object
- Rack::MiniProfiler::FileStore::FileCache
- Defined in:
- lib/mini_profiler/storage/file_store.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
-
#initialize(path, prefix) ⇒ FileCache
constructor
A new instance of FileCache.
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 |