Reputation: 2005
I want to enable caching in Twig. I found how to do this during creating of a Twig Environment object
$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
But i want to add caching after object is constructed. Now can i do this?
I have the class that inherits Twig
class MyTwig extends Twig_Environment {
public function someFunction() {
// enable cache there
}
}
I need to enable cache inside the function someFunction()
Upvotes: 0
Views: 388
Reputation: 2048
Take a look inside Environment.php, there is a method called setCache
. So I guess you can simply:
public function loadTwig() {
// ...
$this->twig = new Twig_Environment($loader, $params);
// ...
}
public function someFunction() {
// ...
$this->twig->setCache('/path/to/compilation_cache');
// ...
}
Upvotes: 2