开发者

How to cache layout content in Zend Framework

How would you implement caching of the layout content in Zend Framework?

In the layout.phtml I do: $this->layout->content and I want the content of this variable to be cached. The other widgets from the layout开发者_运维问答 are real time (or cached other way).

The best bets are:

  • static cache (the fastest)
  • page cache

My pages already have unique page id (canonical), so it could be used as page cache tag.

Potentially looks like I have to overload __get property of the layout.

I'm trying to do something like the layout of SO (user panel at the top, rest cached for all).

I assume, site should work without JavaScript.


You might want to have a look at the Front Controller Cache plugin weierophinney describes. The problem probably is that you don't want the script to stop on cache hit. So you don't exit; the the script, you could work with $request->setDispatched(true) within the plugin. (You'd need a new request-object for every different cacheable).
Another approach could be that you don't use the dispatchLoopStartup but the preDispatch in your plugin and reset the dispatching there.
They way to go actually depends on how you load all the other stuff (be it cached or not). (E.g. the ActionStack pushes a new request to the dispatcher).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜