Class: Sprockets::Cache::FileStore
- Inherits:
-
Object
- Object
- Sprockets::Cache::FileStore
- Defined in:
- lib/sprockets/cache/file_store.rb
Overview
Instance Method Summary collapse
-
#[](key) ⇒ Object
Lookup value in cache.
-
#[]=(key, value) ⇒ Object
Save value to cache.
-
#initialize(root) ⇒ FileStore
constructor
A new instance of FileStore.
Constructor Details
Instance Method Details
#[](key) ⇒ Object
Lookup value in cache
17 18 19 20 |
# File 'lib/sprockets/cache/file_store.rb', line 17 def [](key) pathname = @root.join(key) pathname.exist? ? pathname.open('rb') { |f| Marshal.load(f) } : nil end |
#[]=(key, value) ⇒ Object
Save value to cache
23 24 25 26 27 28 29 |
# File 'lib/sprockets/cache/file_store.rb', line 23 def []=(key, value) # Ensure directory exists FileUtils.mkdir_p @root.join(key).dirname @root.join(key).open('w') { |f| Marshal.dump(value, f)} value end |