开发者

Zend cache frontend options compared: are they saving same amount of resources?

Zend_Cache can be configured to cache several types of output, including 开发者_JAVA技巧
the results of function calls, the results of object and static method calls, 
entire pages, and configuration data.

-I have a doubt.Given this controller/view structure:

Index controller:

class IndexController extends Zend_Controller_Action
{
 public function indexAction()
 {
  //Post is a db_table model
  $post_manager=new Post();
  $Post=$post_manager->getFirstPost();
  $this->view->post=$Post;
 }
}  

-Index view:

echo $this->post->title;
echo $this->post->text;

I could decide,correct me if wrong, for caching my Database RecordSet (directly in my Index controller) or for caching my output (in my view index.phtml ) using Output frontend.

Are the above solutions saving the same amount of my system resources?

thanks

Luca


Both save you some resources. You can cache either of them or both. It's highly dependant on your exact code. Some structures can't be cached (SimpleXML comes in mind - like twitter feed), so you need to cache the output.

You can cache your model's calls. You can cache your config.

But still I think this is kind of a premature optimalization (which is root of all evil)

Update: I'd selectively cache the output.

In controller i would go through the items and check if the item has cache, if so, assign it to some output variable, otherwise fetch from DB. Then in view echo the preloaded value or render the partial. I assume that rendering the data is the bottleneck.

But in the end I guess that the best solution is caching the whole output of the whole posts section. If it changes like once a day, or even once an hour it's huge benefit. I would check in controller if cache exists, if it does, assign it to the view variable and turn some flag ($this->view->hasCachedPosts = true). Then in view render the cached response. If cache is missed load the needed data. Also don't forget to insert cache cleaning into models update/delete/insert methods.

If you have many changes per minute (huge audience), even a 30s caching would help. And if you have small audience, than caching should last longer.

The more your content changes, the smaller parts you need to cache, so that the big chunks are not periodicaly invalidated.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜