Pages

Cache Your Zend Framework Config to Improve Performance, zend cache configuration

Caching in Zend Framework is operated by frontends while cache records are stored through backend adapters (File, Sqlite, Memcache...) through a flexible system of IDs and tags. Using those, it is easy to delete specific types of records afterwards (for example: "delete all cache records marked with a given tag").

How to zend cache configuration:
Copy this to Bootstrap.php
protected function _initMyRoutes() {

  // Disable auto buffer and instead leave it to the cache


Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true);

  $frontendOptionsCore = array(

  'automatic_serialization' => true,

  'lifetime' => 600

  );


$frontendOptionsPage = array(

  'automatic_serialization' => true,

  'lifetime' => 600,

  'default_options' => array(

  'cache_with_get_variables' => true,

  'cache_with_session_variables' => true,

  'cache_with_cookie_variables' => true,

  'make_id_with_get_variables' => true,

  'make_id_with_session_variables' => true,

  'make_id_with_cookie_variables' => false

  )

  );


$backendOptions = array('cache_dir' => APPLICATION_PATH . '/Cache');

  $coreCache = Zend_Cache::factory('Core', 'File', $frontendOptionsCore, $backendOptions);

  $pageCache = Zend_Cache::factory('Page', 'File', $frontendOptionsPage, $backendOptions);


// Start running the page cache immediately

  $pageCache->start();


// Set global cache objects

  Zend_Registry::set('coreCache', $coreCache);

  Zend_Registry::set('pageCache', $pageCache);


// Start running the DB/Core cache

  Zend_Db_Table_Abstract::setDefaultMetadataCache(Zend_Registry::get('coreCache'));

  }

No comments:

Post a Comment