Zend页面缓存类似于smarty?

发布于 2024-08-25 10:46:36 字数 1736 浏览 4 评论 0原文

我有办法让 zend_cache 对待前端视图类似于 smarty 吗?我想减少加载时间,页面缓存似乎是做到这一点的最佳方法。

它还需要类似于 {nocache} 的东西。

好的,我现在有了: Bootstrap.php

    protected function _initCache() {

    $this->bootstrap('locale');
    $locale = $this->getResource('locale');

    $front = array ( 'lifetime' => 1800,
    'automatic_serialization' => false,
    'caching' => true,
    'cache_id_prefix' => 'ec_',
    'debug_header' => true, 

    'default_options' 
        => array ('cache_with_get_variables' => true,
        'cache_with_post_variables' => false,
        'cache_with_session_variables' => false,
        'cache_with_cookie_variables' => false ),
    );

    $back = array('cache_dir' => '../data/Cache/'.$locale);

    $cache = Zend_Cache::factory('Page', 'File', $front, $back);
    $cache->start();
    Zend_Registry::set('cache', $cache);
    return $cache;
}

但是,唯一一次命中我的缓存的是使用如下代码:

$cache = Zend_Registry::get('cache');

            if (!$data = $cache->load('sidebar_'.$module.'_'.$controller)) {
                $data['Studio']     = Eurocreme_Studio::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => COUNT_HIGH));
                $data['Movie']      = Eurocreme_Movie::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
                $data['Gallery']    = Eurocreme_Gallery::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
                $data['Category']   = Eurocreme_Category::load_tree(0);
                $cache->save($data, 'my_view_helper_sidebar_'.$module.'_'.$controller);
            }

我希望捕获整个视图。

有谁有关于如何充分实施它的工作示例吗?这些文档并没有真正深入。

I there a way to make zend_cache treat front end view similar to smarty? I would like to reduce load times and page caching seems the best way todo this.

Also it would need something similar to {nocache}.

Okay so I now have: Bootstrap.php

    protected function _initCache() {

    $this->bootstrap('locale');
    $locale = $this->getResource('locale');

    $front = array ( 'lifetime' => 1800,
    'automatic_serialization' => false,
    'caching' => true,
    'cache_id_prefix' => 'ec_',
    'debug_header' => true, 

    'default_options' 
        => array ('cache_with_get_variables' => true,
        'cache_with_post_variables' => false,
        'cache_with_session_variables' => false,
        'cache_with_cookie_variables' => false ),
    );

    $back = array('cache_dir' => '../data/Cache/'.$locale);

    $cache = Zend_Cache::factory('Page', 'File', $front, $back);
    $cache->start();
    Zend_Registry::set('cache', $cache);
    return $cache;
}

However, the only time my cache is hit is with code like:

$cache = Zend_Registry::get('cache');

            if (!$data = $cache->load('sidebar_'.$module.'_'.$controller)) {
                $data['Studio']     = Eurocreme_Studio::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => COUNT_HIGH));
                $data['Movie']      = Eurocreme_Movie::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
                $data['Gallery']    = Eurocreme_Gallery::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
                $data['Category']   = Eurocreme_Category::load_tree(0);
                $cache->save($data, 'my_view_helper_sidebar_'.$module.'_'.$controller);
            }

I was hoping to capture the entire views.

Does anyone have any working examples of how to implement it fully? The docs don't really go in-depth.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烏雲後面有陽光 2024-09-01 10:46:36

您可能需要使用 Zend_Cache_Frontend_OutputZend_Cache_Frontend_Page。来自 Zend Framework 手册

Zend_Cache_Frontend_Output 是一个输出捕获前端。它利用 PHP 中的输出缓冲来捕获 start() 和 end() 方法之间的所有内容。

Zend_Cache_Frontend_Page 与 Zend_Cache_Frontend_Output 类似,但专为完整页面而设计。

You may want to use Zend_Cache_Frontend_Output or Zend_Cache_Frontend_Page. From Zend Framework manual:

Zend_Cache_Frontend_Output is an output-capturing frontend. It utilizes output buffering in PHP to capture everything between its start() and end() methods.

Zend_Cache_Frontend_Page is like Zend_Cache_Frontend_Output but designed for a complete page.

我的奇迹 2024-09-01 10:46:36

您可能正在寻找 Zend_Cache_Frontend_Page。有关详细信息,请参阅 Zend Cache 文档

You are probably looking for Zend_Cache_Frontend_Page. Please refer to Zend Cache docs for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文