Allow CmsObjects to define their own Twig cache key

This commit is contained in:
Samuel Georges 2016-03-21 17:51:14 +11:00
parent 4922d6d284
commit 6e7fa7de88
5 changed files with 33 additions and 3 deletions

View File

@ -373,7 +373,7 @@ class FormController extends ControllerBehavior
protected function createModel()
{
$class = $this->config->modelClass;
$model = new $class();
$model = new $class;
return $model;
}

View File

@ -224,6 +224,21 @@ class CmsObject extends HalcyonModel implements CmsObjectContract
return $this->content;
}
/**
* Returns the key used by the Twig cache.
* @return string
*/
public function getTwigCacheKey()
{
$key = $this->getFilePath();
if ($event = $this->fireEvent('cmsObject.getTwigCacheKey', compact('key'), true)) {
$key = $event;
}
return $key;
}
//
// Internals
//

View File

@ -167,6 +167,15 @@ class ComponentPartial extends Extendable implements CmsObjectContract
return $this->content;
}
/**
* Returns the key used by the Twig cache.
* @return string
*/
public function getTwigCacheKey()
{
return $this->getFilePath();
}
/**
* Returns the file name.
* @return string

View File

@ -54,4 +54,10 @@ interface CmsObject
*/
public function getTwigContent();
}
/**
* Returns the key used by the Twig cache.
* @return string
*/
public function getTwigCacheKey();
}

View File

@ -49,7 +49,7 @@ class Loader implements Twig_LoaderInterface
*/
public function getCacheKey($name)
{
return $this->obj->getFilePath();
return $this->obj->getTwigCacheKey();
}
/**