class Sprockets::Cache::FileStore - sprockets-2.11.3 Documentation

# class Sprockets::Cache::FileStore

A simple file system cache store.

    environment.cache = Sprockets::Cache::FileStore.new("/tmp")

### Public Class Methods

new(root) click to toggle source

    # File lib/sprockets/cache/file_store.rb, line 12
    def initialize(root)
      @root = Pathname.new(root)
    end

### Public Instance Methods

[](key) click to toggle source

Lookup value in cache

    # 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) click to toggle source

Save value to cache

    # 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