LoginSignup
0
2

More than 5 years have passed since last update.

twigで compile済templateのキャッシュを有効にする

Posted at

twigもsmarty同様、内部で .twigを .phpに変換して実行しています。

.tiwgを.phpにコンパイルしたものをキャッシュする仕組みがあってもよさそうなもんですが
ブログなどに公開されている「twigの使い方」系の記事には特に情報が載ってない。

数kb~数十kb 程度のソースコンパイル時間なんて誤さ程度の時間だろうし、対応してないのかなー、とずっと思ってたのですが、そんなことはなかった。

$loader = new Twig_Loader_Filesystem($templateDir);
$cache = new Twig_Cache_Filesystem($templateCacheDir);
$twig = new Twig_Environment($loader, array('cache' => $cache));

当然ながら、$templateCacheDirectory は apache等のweb server や php-fpm等のプログラムから0777でアクセスできる必要があるみたい。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2