【问题标题】:Zend Cache fileZend 缓存文件
【发布时间】:2013-06-11 16:51:37
【问题描述】:

我将 Doctrine 1.2Zend Framework 1 一起使用。

我有很多控制器,布局中有左侧边栏和右侧边栏,活动会话中有访问者和身份验证用户。

我已经做了一个基本的缓存方法,比如:

$frontend= array('lifetime' => 3600);

$backend= array('cache_dir' => '/data/cache/FileName');

$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);

if ((!$result = $cache->load('fileName'))) {
    /* my code here*/
    $cache->save($page, 'fileName');
} else {
    $this->_helper->viewRenderer->setNoRender();
    $this->getResponse()->appendBody($result);
}

但是每次我需要在控制器中兑现页面时,我都会在每个控制器中重复此代码,因此我想创建帮助程序来管理我的现金,用于使用一组参数(例如文件名、寿命、日志在用户,其他)和兑现文件从左侧边栏等布局,并能够删除现金文件。 所以我只从我的控制器调用方法并从一个地方处理它。

在 Zend 框架中构建这种缓存技术助手的最佳方法是什么,如果你有任何 示例请帮助我并为我提供构建它的最佳方法。

谢谢。

【问题讨论】:

    标签: php zend-framework caching helper


    【解决方案1】:

    您可以使用 Zend_Cache_Frontend_Page 并在您的 Zend bootstrap.php 中开始缓存。

    喜欢:

     $frontendOptions = array(
                        'lifetime' => '604800000',
                        'content_type_memorization' => false,
                        'default_options' => array(
                            'cache' => true,
                            'make_id_with_cookie_variables' => false,
                            'make_id_with_session_variables' => false,
                            'cache_with_get_variables' => true,
                            'cache_with_post_variables' => true,
                            'cache_with_session_variables' => true,
                            'cache_with_files_variables' => true,
                            'cache_with_cookie_variables' => true,
                        ),
                        'regexps' => array(
                            '$' => array('cache' => true),
                        )
                    );
    
                    $backendOptions = array('cache_dir' => $yourDirectoryPath);
                    $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
                    $cache->start();
    

    按照 Zend Cache 手册中的教程进行操作

    http://framework.zend.com/manual/1.12/en/zend.cache.theory.html

    【讨论】:

      【解决方案2】:

      你真的需要缓存页面,为什么不缓存昂贵的数据?

      在 Zend Framework 1 中,插件被加载到每个控制器上,ZF1 Custom Plugins

      或仅在某些地方使用动作助手ZF1 Action Helpers

      【讨论】:

      • 谢谢,我会试试你的解决方案
      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 2011-04-14
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      相关资源
      最近更新 更多