dongxuanjiao0795 2010-05-30 16:20
浏览 40
已采纳

如何在这个特定问题上使用Zend Cache

I have an action that renders two different view scripts based on whether the user is logged in or not.

class IndexController extends Zend_Controller_Action
{
    ....
        public function indexAction()
            {

                $auth = Zend_Auth::getInstance();
                if($auth->hasIdentity())
                {
                    $this->render('indexregistered');
                    return; 
                }
                else {
                    $this->render('indexpublic');
                    return;
            }   
    }   
    ....    
} 

I have seen quite some useful examples on how to use the Zend Cache and they seem to be based on the fact that the action renders one particular script.

What am really looking at is the best approach to cache the indexpublic script which gets quite some hits and I would really like to avoid the Zend MVC overhead if possible.

  • 写回答

2条回答 默认 最新

  • douwen1313 2010-05-30 19:13
    关注

    Zend_Cache_Frontend_Output may be what you need here:

    if (!($cache->start('indexpublic'))) {
        // output everything as usual
        $this->render('indexpublic');
        $cache->end(); // output buffering ends   
    }
    

    Before that, the cache manager needs to be initialized (could be in the bootstrap), e.g:

    $frontendOptions = array(
       'lifetime' => 7200
    );
    
    $backendOptions = array(
        'cache_dir' => '/tmp/'
    );
    
    // getting a Zend_Cache_Frontend_Output object
    $cache = Zend_Cache::factory('Output',
                                 'File',
                                 $frontendOptions,
                                 $backendOptions);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改