class Sprockets::Index

`Cached` is a special cached version of `Environment`.

The expection is that all of its file system methods are cached for the instances lifetime. This makes `Cached` much faster. This behavior is ideal in production environments where the file system is immutable.

`Cached` should not be initialized directly. Instead use `Environment#cached`.

Public Class Methods

new(environment) click to toggle source
# File lib/sprockets/cached_environment.rb, line 14
def initialize(environment)
  initialize_configuration(environment)

  @cache   = environment.cache
  @stats   = Hash.new { |h, k| h[k] = _stat(k) }
  @entries = Hash.new { |h, k| h[k] = _entries(k) }
  @uris    = Hash.new { |h, k| h[k] = _load(k) }

  @processor_cache_keys  = Hash.new { |h, k| h[k] = _processor_cache_key(k) }
  @resolved_dependencies = Hash.new { |h, k| h[k] = _resolve_dependency(k) }
end

Public Instance Methods

_entries(path)

Internal: Cache Environment#entries

Alias for: entries
_load(uri)
Alias for: load
_processor_cache_key(str)

Internal: Cache Environment#processor_cache_key

Alias for: processor_cache_key
_resolve_dependency(str)

Internal: Cache Environment#resolve_dependency

Alias for: resolve_dependency
_stat(path)

Internal: Cache Environment#stat

Alias for: stat
cached() click to toggle source

No-op return self as cached environment.

# File lib/sprockets/cached_environment.rb, line 27
def cached
  self
end
Also aliased as: index
entries(path) click to toggle source
# File lib/sprockets/cached_environment.rb, line 34
def entries(path)
  @entries[path]
end
Also aliased as: _entries
index()
Alias for: cached
load(uri) click to toggle source
# File lib/sprockets/cached_environment.rb, line 46
def load(uri)
  @uris[uri]
end
Also aliased as: _load
processor_cache_key(str) click to toggle source
# File lib/sprockets/cached_environment.rb, line 52
def processor_cache_key(str)
  @processor_cache_keys[str]
end
Also aliased as: _processor_cache_key
resolve_dependency(str) click to toggle source
# File lib/sprockets/cached_environment.rb, line 58
def resolve_dependency(str)
  @resolved_dependencies[str]
end
Also aliased as: _resolve_dependency
stat(path) click to toggle source
# File lib/sprockets/cached_environment.rb, line 40
def stat(path)
  @stats[path]
end
Also aliased as: _stat

Private Instance Methods

config=(config) click to toggle source

Cache is immutable, any methods that try to change the runtime config should bomb.

# File lib/sprockets/cached_environment.rb, line 65
def config=(config)
  raise RuntimeError, "can't modify immutable cached environment"
end