class Sprockets::CachedEnvironment
`CachedEnvironment` 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 `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 14 def initialize(environment) initialize_configuration(environment) @cache = environment.cache @stats = {} @entries = {} @uris = {} @processor_cache_keys = {} @resolved_dependencies = {} end
Public Instance Methods
cached()
click to toggle source
No-op return self as cached environment.
# File lib/sprockets/cached_environment.rb, line 26 def cached self end
Also aliased as: index
entries(path)
click to toggle source
Internal: Cache Sprockets::PathUtils#entries
Calls superclass method
Sprockets::PathUtils#entries
# File lib/sprockets/cached_environment.rb, line 32 def entries(path) @entries[path] ||= super(path) end
load(uri)
click to toggle source
Internal: Cache Sprockets::Environment#load
Calls superclass method
Sprockets::Loader#load
# File lib/sprockets/cached_environment.rb, line 42 def load(uri) @uris[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 47 def processor_cache_key(str) @processor_cache_keys[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 52 def resolve_dependency(str) @resolved_dependencies[str] ||= super(str) end
stat(path)
click to toggle source
Internal: Cache Sprockets::PathUtils#stat
Calls superclass method
Sprockets::PathUtils#stat
# File lib/sprockets/cached_environment.rb, line 37 def stat(path) @stats[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 59 def config=(config) raise RuntimeError, "can't modify immutable cached environment" end