class Sprockets::Cache::FileStore
environment.cache = Sprockets::Cache::FileStore.new(“tmp/sprockets”)
A simple file system cache store.
def [](key)
def [](key) pathname = path_for(key) pathname.exist? ? pathname.open('rb') { |f| Marshal.load(f) } : nil end
def []=(key, value)
def []=(key, value) path_for(key).open('w') { |f| Marshal.dump(value, f)} value end
def initialize(root)
def initialize(root) @root = Pathname.new(root) # Ensure directory exists FileUtils.mkdir_p @root end
def path_for(key)
The key may include some funky characters so hash it into
Returns path for cache key.
def path_for(key) @root.join(::Digest::MD5.hexdigest(key)) end