module Sprockets::Loader
def fetch_asset_from_dependency_cache(unloaded, limit = 3)
When this happens the dependencies for the returned asset are added to the "history", and older
the block is yielded to and expected to return a valid asset.
If no history is present, or if none of the histories could be resolved to a valid asset then,
history will be saved with the dependency that found a valid asset moved to the front.
yielded to the passed block which is responsible for loading the asset. If found, the existing
If a "history" of dependencies is present in the cache, each version of "history" will be
generated present in the system.
Multiple versions are stored since sprockets keeps the last `limit` number of assets
Where the first entry is a Set of dependencies for last generated version of that asset.
"file-digest:///Full/path/app/assets/stylesheets"]]
"processors:type=text/css&file_digesttype=text/css&pipeline=self",
"file-digest:///Full/path/app/assets/stylesheets/application.css",
[["environment-version", "environment-paths", "processors:type=text/css&file_type=text/css",
For example a history array may look something like this
are used.
compilation, such as the VERSION of sprockets (i.e. the environment) and what "processors"
may rely on jquery.js (so jquery.js is a depndency), or other factors that may affect
to compile. In this case A dependency can refer to either an asset i.e. index.js
from the cache a "history" which is an array of unresolved "dependencies" that the asset needs
This method attempts to retrieve the last `limit` number of histories of an asset
stored in the cache
limit - A Fixnum which sets the maximum number of versions of "histories"
unloaded - An UnloadedAsset
Internal: Retrieves an asset based on its digest
def fetch_asset_from_dependency_cache(unloaded, limit = 3) key = unloaded.dependency_history_key history = cache.get(key) || [] history.each_with_index do |deps, index| expanded_deps = deps.map do |path| path.start_with?("file-digest://") ? expand_from_root(path) : path end if asset = yield(expanded_deps) cache.set(key, history.rotate!(index)) if index > 0 return asset end end asset = yield deps = asset[:metadata][:dependencies].dup.map! do |uri| uri.start_with?("file-digest://") ? compress_from_root(uri) : uri end cache.set(key, history.unshift(deps).take(limit)) asset end