code used in the dispatcher: Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Auth'); Zend_Loader::loadClass('Zend_Cache_Backend_Memcached'); Zend_Loader::loadClass('Zend_Log'); Zend_Loader::loadClass('Zend_Log_Writer_Stream'); Zend_Loader::loadClass('Zend_Cache_Core'); $CacheLog = new Zend_Log(); $CacheLog->addWriter( new Zend_Log_Writer_Stream( 'file:///tmp/prememcache.log' )); .....zend autentication..... if (!Zend_Auth::getInstance()->hasIdentity()){ $Frontend = array( 'caching' => true, 'cache_id_prefix' => 'myApp', 'logging' => true, 'logger' => $CacheLog, 'write_control' => true, 'automatic_serialization' => true, 'ignore_user_abort' => true );
}else{
$oFrontend = array( 'caching' => false, 'cache_id_prefix' => 'myApp', 'logging' => true, 'logger' => $CacheLog, 'write_control' => true, 'automatic_serialization' => true, 'ignore_user_abort' => true ); } $oBackend = array( 'servers' => array( array( 'host' => '127.0.0.1', 'port' => '11211' ) ), 'compression' => true ); $oCache = Zend_Cache::factory( 'Core','Memcached',$Frontend, $Backend ); $config = new Zend_Config_Ini('applicationsFrame/config.ini', 'general'); $registry = Zend_Registry::getInstance(); $registry->set('config', $config); $registry->set('Cache',$Cache); ....dispatcher....controller...model...... Search model cached query sample using the above mamecache passing by an appropriate search controller Esempio di query utilizzando la mamcache inizializzata sopra in un modello di ricerca chiaramente richiamato da un apposito controller $order="id DESC"; $where[]="text = '$ParamTesto'"; $where[]="option = '$ParamOption'"; $PARAMsEACH=md5($ParamTesto.$ParamOption); $Cache = Zend_Registry::get('Cache'); $CacheId= 'Search'.$PARAMsEACH; if ( ! $Cache->test( $CacheId ) ) { $rows=$this->fetchAll($where,$order); $Cache->save( $rows, $CacheId ); } else { $rows = $Cache->load( $CacheId ); } |