开发者

Minimalistic PHP template engine with caching but not Smarty?

开发者 https://www.devze.com 2022-12-25 18:55 出处:网络
There are loads of questions for \"the right\" PHP template engine, but none of them is focused on caching.

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'开发者_Python百科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

  • To answer your question I don't know 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

  • I believe that Twig is a pretty solid template enine and that you can implement caching on top of that easily.
  • Just cache it in APC. When storing put a TTL(Time To Live) on it of. Then try to get it from cache.
  • I assume you already have APC 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消