【问题标题】:How do you cache pagination result & doctrine?你如何缓存分页结果和学说?
【发布时间】:2011-12-16 17:09:32
【问题描述】:

我将 Zend Framework 和 Zend_Paginator 与 Doctrine 2 和 DoctrineExtensions Paginate Adapter 一起使用。

我需要缓存我的结果,但是我不知道我应该在哪里做这个。

在存储库中执行此操作对我来说似乎合乎逻辑,但我尝试过,但它不适用于分页器适配器。

你会怎么走?

【问题讨论】:

    标签: zend-framework caching doctrine-orm zend-paginator


    【解决方案1】:

    查看Zend_Cache。有一些不同的适配器,包括文件、数据库和 memcached - 但处理它的一般方式是这样的:

    $frontendOptions = array(
       'lifetime' => 7200, // cache lifetime of 2 hours
       'automatic_serialization' => true
    );
    
    $backendOptions = array(
        'cache_dir' => './tmp/' // Directory where to put the cache files
    );
    
    // getting a Zend_Cache_Core object
    $cache = Zend_Cache::factory('Core',
                                 'File',
                                 $frontendOptions,
                                 $backendOptions);
    
    if( ($result = $cache->load('myresult')) === false ) {
      // fetch $result
      $cache->save($result, 'myresult');
    }
    

    $result 不是缓存变量。

    【讨论】:

    • 嗨,我希望它可以工作,因为结果包装了 PDO 实例,我们不能直接从 Doctrine 或 Paginator 实例中执行此操作。
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2016-03-31
    • 1970-01-01
    • 2012-08-03
    相关资源
    最近更新 更多