36 $this->asset->ensureFilter($filter);
41 return $this->asset->getFilters();
46 $this->asset->clearFilters();
52 if ($this->cache->has($cacheKey)) {
53 $this->asset->setContent($this->cache->get($cacheKey));
58 $this->asset->load($additionalFilter);
59 $this->cache->set($cacheKey, $this->asset->getContent());
65 if ($this->cache->has($cacheKey)) {
66 return $this->cache->get($cacheKey);
69 $content = $this->asset->dump($additionalFilter);
70 $this->cache->set($cacheKey, $content);
77 return $this->asset->getContent();
82 $this->asset->setContent($content);
87 return $this->asset->getSourceRoot();
92 return $this->asset->getSourcePath();
97 return $this->asset->getSourceDirectory();
102 return $this->asset->getTargetPath();
107 $this->asset->setTargetPath($targetPath);
112 return $this->asset->getLastModified();
117 return $this->asset->getVars();
122 $this->asset->setValues($values);
127 return $this->asset->getValues();
149 if ($additionalFilter) {
151 $asset->ensureFilter($additionalFilter);
154 $cacheKey =
$asset->getSourceRoot();
155 $cacheKey .=
$asset->getSourcePath();
156 $cacheKey .=
$asset->getTargetPath();
157 $cacheKey .=
$asset->getLastModified();
159 foreach (
$asset->getFilters() as $filter) {
161 $cacheKey .= $filter->hash();
163 $cacheKey .= serialize($filter);
167 if ($values =
$asset->getValues()) {
169 $cacheKey .= serialize($values);
172 return md5($cacheKey.$salt);
Caches an asset to avoid the cost of loading and dumping.
getLastModified()
Returns the time the current asset was last modified.
setTargetPath($targetPath)
Sets the URL for the current asset.
setContent($content)
Sets the content of the current asset.
getFilters()
Returns an array of filters currently applied.
getContent()
Returns the loaded content of the current asset.
getSourcePath()
Returns the relative path for the source asset.
getTargetPath()
Returns the URL for the current asset.
setValues(array $values)
Sets the values for the asset's variables.
dump(FilterInterface $additionalFilter=null)
Applies dump filters and returns the asset as a string.
ensureFilter(FilterInterface $filter)
Ensures the current asset includes the supplied filter.
clearFilters()
Clears all filters from the current asset.
static getCacheKey(AssetInterface $asset, FilterInterface $additionalFilter=null, $salt='')
Returns a cache key for the current asset.
getValues()
Returns the current values for this asset.
getSourceRoot()
Returns an absolute path or URL to the source asset's root directory.
getSourceDirectory()
Returns the asset's source directory.
load(FilterInterface $additionalFilter=null)
Loads the asset into memory and applies load filters.
__construct(AssetInterface $asset, CacheInterface $cache)
getVars()
Returns an array of variable names for this asset.
An exception for terminatinating execution or to throw for unit testing.
An asset has a mutable URL and content and can be loaded and dumped.
Interface for a cache backend.
A filter manipulates an asset at load and dump.
A filter can implement a hash function.