class Sprockets::CachedEnvironment

‘CachedEnvironment` is a special cached version of `Environment`.

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

‘CachedEnvironment` 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 15
def initialize(environment)
  initialize_configuration(environment)

  @cache   = environment.cache
  @stats   = Concurrent::Map.new
  @entries = Concurrent::Map.new
  @uris    = Concurrent::Map.new
  @processor_cache_keys = Concurrent::Map.new
  @resolved_dependencies = Concurrent::Map.new
end

Public Instance Methods

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

Internal: Cache Environment#entries

Calls superclass method
# File lib/sprockets/cached_environment.rb, line 33
def entries(path)
  @entries.fetch_or_store(path) { super(path) }
end
index()
Alias for: cached
load(uri) click to toggle source

Internal: Cache Environment#load

Calls superclass method
# File lib/sprockets/cached_environment.rb, line 43
def load(uri)
  @uris.fetch_or_store(uri) { super(uri) }
end
processor_cache_key(str) click to toggle source

Internal: Cache Environment#processor_cache_key

Calls superclass method
# File lib/sprockets/cached_environment.rb, line 48
def processor_cache_key(str)
  @processor_cache_keys.fetch_or_store(str) { super(str) }
end
resolve_dependency(str) click to toggle source

Internal: Cache Environment#resolve_dependency

Calls superclass method
# File lib/sprockets/cached_environment.rb, line 53
def resolve_dependency(str)
  @resolved_dependencies.fetch_or_store(str) { super(str) }
end
stat(path) click to toggle source

Internal: Cache Environment#stat

Calls superclass method
# File lib/sprockets/cached_environment.rb, line 38
def stat(path)
  @stats.fetch_or_store(path) { super(path) }
end

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 60
def config=(config)
  raise RuntimeError, "can't modify immutable cached environment"
end