class Sprockets::CachedEnvironment
‘Environment#cached`.
`Cached` should not be initialized directly. Instead use
is immutable.
behavior is ideal in production environments where the file system
for the instances lifetime. This makes `Cached` much faster. This
The expection is that all of its file system methods are cached
`Cached` is a special cached version of `Environment`.
def asset_dependency_graph_cache_key(uri)
def asset_dependency_graph_cache_key(uri) filename, _ = AssetURI.parse(uri) [ 'asset-uri-dep-graph', VERSION, self.version, self.paths, uri, file_digest(filename) ] end
def asset_uri_cache_key(uri)
def asset_uri_cache_key(uri) [ 'asset-uri', VERSION, self.version, uri ] end
def cached
def cached self end
def entries(path)
def entries(path) @entries[path] end
def file_digest(path)
def file_digest(path) @digests[path] end
def get_asset_dependency_graph_cache(key)
def get_asset_dependency_graph_cache(key) return unless cached = cache._get(key) paths, digest, uri = cached if files_digest(paths) == digest cache._get(asset_uri_cache_key(uri)) end end
def initialize(environment)
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) } @digests = Hash.new { |h, k| h[k] = _file_digest(k) } @uris = Hash.new { |h, k| h[k] = _load(k) } end
def load(uri)
def load(uri) @uris[uri] end
def load_asset_by_id_uri(uri)
def load_asset_by_id_uri(uri) cache.fetch(asset_uri_cache_key(uri)) do super end end
def load_asset_by_uri(uri)
def load_asset_by_uri(uri) dep_graph_key = asset_dependency_graph_cache_key(uri) if asset = get_asset_dependency_graph_cache(dep_graph_key) asset else asset = super set_asset_dependency_graph_cache(dep_graph_key, asset) asset end end
def mutate_config(*args)
Cache is immutable, any methods that try to clear the cache
def mutate_config(*args) raise RuntimeError, "can't modify immutable cached environment" end
def set_asset_dependency_graph_cache(key, asset)
def set_asset_dependency_graph_cache(key, asset) uri = asset[:uri] digest, paths = asset[:metadata].values_at(:dependency_sources_digest, :dependency_paths) cache._set(key, [paths, digest, uri]) cache.fetch(asset_uri_cache_key(uri)) { asset } asset end
def stat(path)
def stat(path) @stats[path] end