module Sprockets::Caching
def cache_asset(path)
logical path or fully expanded path. The `&block` is passed
Cache helper method. Takes a `path` argument which maybe a
def cache_asset(path) # If `cache` is not set, return fast if cache.nil? yield # Check cache for `path` elsif (asset = asset_from_hash(cache_get_hash(path.to_s, digest.hexdigest))) && asset.fresh? asset # Otherwise yield block that slowly finds and builds the asset elsif asset = yield hash = {} asset.encode_with(hash) # Save the asset to its path cache_set_hash(path.to_s, digest.hexdigest, hash) # Since path maybe a logical or full pathname, save the # asset its its full path too if path.to_s != asset.pathname.to_s cache_set_hash(asset.pathname.to_s, digest.hexdigest, hash) end asset end end