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_hexdigest(filename)
  ]
end

def asset_digest_uri_cache_key(uri)

def asset_digest_uri_cache_key(uri)
  [
    'asset-digest-uri',
    VERSION,
    self.version,
    uri
  ]
end

def build_asset_by_digest_uri(uri)

def build_asset_by_digest_uri(uri)
  cache.fetch(asset_digest_uri_cache_key(uri)) do
    super
  end
end

def build_asset_by_uri(uri)

def build_asset_by_uri(uri)
  dep_graph_key = asset_dependency_graph_cache_key(uri)
  dependency_paths, dependency_digest, digest_uri = cache._get(dep_graph_key)
  if dependency_paths && dependency_digest && digest_uri
    if dependencies_hexdigest(dependency_paths) == dependency_digest
      if asset = cache._get(asset_digest_uri_cache_key(digest_uri))
        return asset
      end
    end
  end
  asset = super
  dependency_digest, dependency_paths = asset[:metadata].values_at(:dependency_digest, :dependency_paths)
  cache._set(dep_graph_key, [dependency_paths, dependency_digest, asset[:uri]])
  cache.fetch(asset_digest_uri_cache_key(asset[:uri])) { asset }
  asset
end

def cached

No-op return self as cached environment.
def cached
  self
end

def entries(path)

def entries(path)
  @entries[path]
end

def file_hexdigest(path)

def file_hexdigest(path)
  @hexdigests[path]
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) }
  @hexdigests = Hash.new { |h, k| h[k] = _file_hexdigest(k) }
end

def mutate_config(*args)

should bomb.
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 stat(path)

def stat(path)
  @stats[path]
end