views:

16

answers:

1

I search a good resources with examples to use a doctrine memcached and zend framework.

i search in google but not found, i need resource that Combine all this things.

using Doctrine_Cache_Memcache in zend framework.

thanks

+1  A: 

For ZF and Doctrine integration see: beberlei's zf-doctrine at GitHub

To enable cache, in your application 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;
    }

Of course, you need to have apc, memcache and memcached installed first.

takeshin
@takeshin thanks , when i call to this function _initDoctrineCache ? only first time , every time i want to cache query , if you can show me the uses of this function in caching sql doctrine queries
Haim Evgi
@Haim This function is placed in Bootstrap, so it automatically runs. No need to call it manually.
takeshin