Class: Sprockets::Cache::FileStore

### Home Classes Methods

### In Files

- lib/sprockets/cache/file_store.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::AssetAttributes
- Sprockets::Base
- Sprockets::BundledAsset
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Caching
- Sprockets::CharsetNormalizer
- Sprockets::CircularDependencyError
- Sprockets::ClosureCompressor
- Sprockets::Compressing
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::DirectiveProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsTemplate
- Sprockets::EncodingError
- Sprockets::EngineError
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::Manifest
- Sprockets::Mime
- Sprockets::NotImplementedError
- Sprockets::Paths
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::SassCacheStore
- Sprockets::SassCompressor
- Sprockets::SassFunctions
- Sprockets::SassImporter
- Sprockets::SassTemplate
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::UglifierCompressor
- Sprockets::UnserializeError
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.