搜索良好的资源,用doctrine 1.2和zend框架实现memcached

时间:2010-08-24 13:43:34

标签: zend-framework memcached doctrine-1.2

我使用示例搜索一个好的资源来使用doctrine memcached和zend框架。

我在谷歌搜索但未找到,我需要资源来结合所有这些东西。

在zend框架中使用Doctrine_Cache_Memcache

感谢

1 个答案:

答案 0 :(得分:2)

对于ZF和Doctrine集成,请参阅:beberlei's zf-doctrine at GitHub

要在您的应用Bootstrap.php中启用缓存:

public function _initDoctrineCache()
{
    $this->bootstrap('doctrine');

    $manager = Doctrine_Manager::getInstance();

    $cacheDriver = null;

    if (extension_loaded('memcache')) {
        $servers = array(
            'host' => 'localhost',
            'port' => 11211,
            'persistent' => true
        );

        $cacheDriver = new Doctrine_Cache_Memcache(array(
                    'servers' => $servers,
                    'compression' => false
                        )
        );
    } else if (function_exists('apc_add')) {
        $cacheDriver = new Doctrine_Cache_Apc();
    }

    if (null !== $cacheDriver) {
        //$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
        $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
        $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 120); // in seconds
    }

    return $cacheDriver;
    }

当然,您需要先安装apcmemcachememcached