There are loads of questions for “the right” PHP template engine, but none of them is focused on caching.
Does anybody know a lightweight, high-quality, PHP 5 based template engine that does the following out of the box:
-
Low-level templating functions (Replacements, loops, and filtering, maybe conditionals)
-
Caching of the parsed results with the possibility to set an individual TTL per item, and of course to force a reload programmatically
-
Extremely easy usage (like Smarty’s)
-
Modest in polluting the namespace (the ideal solution would be one class to interact with from the outside application)
But not Smarty. I have nothing against, and often use, Smarty, but I am looking for something a bit simpler and leaner.
I took a look at Fabien Potencier’s Twig that looks very nice and compiles templates into PHP code, but it doesn’t do any actual caching beyond that.
I need and want a template engine, as I need to completely separate code and presentation in a way that a HTML designer can understand later on, so please no fundamental discussions about whether template engines in PHP make sense. Those discussions are important, but there are specific questions for that issue.
Template Engine with Caching
a template which support all your requirements. Hopefully somebody else can help you with that. But after a little bit of searching I found TinyButStrong. On there site they mention it has a
cache system. I can’t find what kind of caching they implement(Disc/Memory/Database). It should cache in memory for truly speedups).Implement Caching yourself
template enine and that you can
implement caching on top of that
easily.
storing put a TTL(Time To Live)
on it of. Then try to get it
from cache.
installed, if you are concerned about
performance (caching). Then the
first thing you should install for
performance is APC(A must because it also stores compiled PHP files in memory. This means it does not have to recompile every time). If you can not install APC then maybe you could check out
Cache-Lite. I really liked this pear package for it’s simplicity/good documentation.