Use of Zend Cache

Zend Cache will help you to prevent the time taken for heavy sql query.

Lines to be added in bootstrap file:

$backend= 'File';$frontend = 'Core';
$frontendOptions= array('lifetime' => 7200);
$backendOptions= array('cache_dir' => 'public/temp');
$cache = Zend_Cache::factory($frontend, $backend,$frontendOptions,$backendOptions);

Lines to be added in init function of your controller file:

$this->cache = Zend_Registry::get('cache');

Lines to use the Zend Cache:

$data = $this->cache->load('TempVar');
if($data === FALSE)
$query=$this->db->query("SELECT * FROM table_name");
$data = $query->fetchAll();
$this->view->users = $data

Post a Comment