zend-framework - 不止一个 Zend_Cache 配置?

标签 zend-framework zend-cache

Zend_Cache 是否可以有两个不同的缓存实例? 例如,如果我想要一组文件永久存储,除非我删除它们,而另一组文件每分钟就会失效 - 我可以这样做吗?

Everywhere I look我总是看到只使用一种前端和后端配置。

谢谢!

最佳答案

您只需创建两个不同的 Zend_Cache 实例并将它们粘贴到方便的地方。我做了一次类似的事情,在 boostrap 中实例化缓存实例,然后将它们粘贴到注册表中,如下所示:

protected function _initCache(){
    $this->bootstrap('config');
    $config = Zend_Registry::get('config')->myapp->cache;

    $cache = Zend_Cache::factory(
      $config->frontend->name,
      $config->backend->name,
      $config->frontend->opts->toArray(),
      $config->backend->opts->toArray()
    );
    Zend_Registry::set('cache',$cache);
    return $cache;
  }

  protected function _initUserCache(){
    $this->bootstrap('config');
    $config = Zend_Registry::get('config')->myapp->othercache;

    $cache = Zend_Cache::factory(
      $config->frontend->name,
      $config->backend->name,
      $config->frontend->opts->toArray(),
      $config->backend->opts->toArray()
    );
    Zend_Registry::set('othercache',$cache);
    return $cache;

  }

因此,Zend_Cache 的设计实际上并没有限制您可以拥有的不同缓存的数量。您可以独立配置它们,使用您喜欢的任何前端和后端。

关于zend-framework - 不止一个 Zend_Cache 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10464855/

相关文章:

zend-framework - Zend_Layout 和/或 Smarty

php - Zend Framework 缓存存放位置

zend-framework - Zend Framework 的后端缓存与前端缓存有何不同

php - 如何在 Magento 中使用扩展/模块创建自定义订单状态

php - 掩盖信用卡和银行账户信息

zend-framework - Zend_Cache 缓存整个站点而不是 Controller

php - Redis缓存时报错 "Connection read timed out"

zend-framework - Zend_Cache_Frontend_Capture 和 Zend_Cache_Frontend_Page 有什么区别

zend-framework - 如何在AND条件内使用OR条件编写Zend db select

php - 如何在 PHP 和 Zend 中使用 Facebook Connect 注销用户?