4rrr 发表于 2015-9-1 14:09:43

Zend中配置Memcached

  protected function _initSession()
    {
      // configure caching backend strategy
      $oBackend = new Zend_Cache_Backend_Memcached(
            array(
                'servers' => array( array(
                  'host' => '192.168.0.100',
                  'port' => '11211'
                ) ),
                'compression' => true
      ) );
         
//      configure caching logger
//      $oCacheLog =new Zend_Log();
//      $oCacheLog->addWriter( new Zend_Log_Writer_Stream( 'file:///c:/pr-memcache.log' ) );
         
      // configure caching frontend strategy
      $oFrontend = new Zend_Cache_Core(
            array(
                'caching' => true,
                'cache_id_prefix' => 'myApp',
                'logging' => false,
//                'logger'=> $oCacheLog,
                'write_control' => true,
                'automatic_serialization' => true,
                'ignore_user_abort' => true
            ) );
         
      // build a caching object
      $oCache = Zend_Cache::factory( $oFrontend, $oBackend );
      Zend_Registry::set('oCache', $oCache);
      /*try{
            $frontendOptions = array('lifeTime' => 7200, // 两小时的缓存生命期   
            'automatic_serialization' => false);
            $backendOptions = array('cache_dir' => 'c://pljava/' // 放缓存文件的目录
            );// 取得一个Zend_Cache_Core 对象
            $cache = Zend_Cache::factory('Output','File', $frontendOptions,$backendOptions);
            
      }catch (Zend_Cache_Exception $e){
            echo $e;
      }
      if(!$cache->start('mypage')) {
            echo 'Hello world! ';
            echo 'This is cached ('.time().') ';
            $cache->end(); // the output is saved and sent to the browser
      }
      echo 'This is never cached ('.time().').';
      */
      
      /*$frontendOptions = array('lifeTime' => 7200);
      $backendOptions = array(array('host' => 'localhost','port' => 11211, 'persistent' => true));
      $cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
      
      if (!$result = $cache->get('time') ){
      $time = date('r');
      echo "generated: " . $time;
      $cache->save($time, 'time');
      } else {
      echo "cache hit: ". $cache->get('time');
      }*/
    }
页: [1]
查看完整版本: Zend中配置Memcached