Issue #0001653: Optimizing WorldCheck cache , using Scores/Cache.php

This commit is contained in:
Aram HARUTYUNYAN 2013-09-26 08:53:29 +00:00
parent 0dad63915a
commit e587b06b71
3 changed files with 43 additions and 51 deletions

View File

@ -1,10 +1,16 @@
<?php
class WorldcheckController extends Zend_Controller_Action
{
protected $wcConfig;
public function init()
{
require_once 'WorldCheck/WsWorldCheck.php';
require_once 'WorldCheck/SessionWorldcheck.php';
require_once '/Scores/Cache.php';
$configWC = new Zend_Config_Ini(APPLICATION_PATH . '/../library/WorldCheck/applicationWC.ini');
$this->wcConfig = $configWC->worldcheck->toArray();
}
/**
@ -45,33 +51,12 @@ class WorldcheckController extends Zend_Controller_Action
$summary->nameIdentifier = $nameIdentifier;
$summary->matchType = 'WATCHLIST';
$configWC = new Zend_Config_Ini(APPLICATION_PATH . '/../library/WorldCheck/applicationWC.ini');
$wcConfig = $configWC->worldcheck->toArray();
//caching
$cache_dir = $wcConfig['cachedir']['path'].$wcConfig['cachedir']['name'];
if (!is_dir($cache_dir)) mkdir($cache_dir, 0777, true);
$frontendOptions = array(
'lifetime' => $wcConfig['cachedir']['lifetime'],
'automatic_serialization' => true
);
$backendOptions = array('cache_dir' => $cache_dir);
$cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions);
if(!($unfilteredWC = $cache->load($nameIdentifier))) {
//get results by lastName
$unfilteredWC = new stdClass();
$unfilteredWC = $wc->getSummariesArr($summary);
//end
$cache->save($unfilteredWC, $nameIdentifier);
}
//end
$cache = new Cache();
$unfilteredWC = $cache->wcCache($this->wcConfig['cachedir'], $wc, "getSummariesArr", $summary, $nameIdentifier);
//check if display all results (search by lastName), or filtered results (search by fullName)
$filtre = $request->getParam('filtre', 'tout');
$resultWC = $unfilteredWC;
Zend_Registry::get('firebug')->info($resultWC);
if ($filtre=='filtered')
{
//get results by fullName (lastName and givenName)
@ -110,7 +95,7 @@ class WorldcheckController extends Zend_Controller_Action
Zend_View_Helper_PaginationControl::setDefaultViewPartial('worldcheck/controls.phtml');
$paginator = Zend_Paginator::factory($resultWC);
$this->view->paginator = $paginator;
$itemCount = $wcConfig['page']['items'];
$itemCount = $this->wcConfig['page']['items'];
$page = $this->_getParam('page', 1);
$ol_number = ($page-1)*$itemCount+1;
@ -162,25 +147,8 @@ class WorldcheckController extends Zend_Controller_Action
$wc = new WsWorldCheck();
// using zend_cache for matchContent
$configWC = new Zend_Config_Ini(APPLICATION_PATH . '/../library/WorldCheck/applicationWC.ini');
$cacheConfig = $configWC->worldcheck->toArray();
$frontendOptions = array(
'lifetime' => $cacheConfig['cachedir']['lifetime'],
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => $cacheConfig['cachedir']['path'].$cacheConfig['cachedir']['name']
);
$cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions);
if(!($content = $cache->load($param->matchIdentifier)))
{
$content = $wc->getDetailsContent($param);
$cache->save($content, $param->matchIdentifier);
}
$cache = new Cache();
$content = $cache->wcCache($this->wcConfig['cachedir'], $wc, "getDetailsContent", $param, $param->matchIdentifier);
$this->view->assign('matchIdentifier', $param->matchIdentifier);
$this->view->assign('content', $content);

View File

@ -3,28 +3,20 @@
<!-- First page link -->
<?php if (isset($this->previous)) { ?>
<a href="<?php echo $this->url(array('page' => $this->first)); ?>"><img src="/themes/default/images/worldcheck/first.png" title='Première page'/></a>
<?php } else { ?>
<span class="disabled"><img src="/themes/default/images/worldcheck/first.png" /></span>
<?php } ?>
<!-- Previous page link -->
<?php if (isset($this->previous)) { ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>"><img src="/themes/default/images/worldcheck/prev.png" title='Page précédente'/></a>
<?php } else { ?>
<span class="disabled"><img src="/themes/default/images/worldcheck/prev.png" /></span>
<?php } ?>
&nbsp;
<!-- Next page link -->
<?php if (isset($this->next)) { ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>"><img src="/themes/default/images/worldcheck/next.png" title='Page suivante'/></a>
<?php } else { ?>
<span class="disabled"><img src="/themes/default/images/worldcheck/next.png" /></span>
<?php } ?>
<!-- Last page link -->
<?php if (isset($this->next)) { ?>
<a href="<?php echo $this->url(array('page' => $this->last)); ?>"><img src="/themes/default/images/worldcheck/last.png" title='Dernière page'/></a>
<?php } else { ?>
<span class="disabled"><img src="/themes/default/images/worldcheck/last.png" /></span>
<?php } ?>
<?php } ?>

View File

@ -124,4 +124,36 @@ class Cache
fclose($fp);
return $result;
}
/**
* Caching WorldCheck Data using Zend_cache
*
* @param array $config (elements: path, name, lifetime)
* @param object $class (object of calling class)
* @param string $function (name of member function)
* @param array $param (arguments of member function)
* @param string $file_name (cache filename)
* @return mixed (array object)
*/
public function wcCache($config, $class, $function, $param, $file_name)
{
//caching
$cache_dir = $config['path'].$config['name'];
if (!is_dir($cache_dir)) mkdir($cache_dir, 0777, true);
$frontendOptions = array(
'lifetime' => $config['lifetime'],
'automatic_serialization' => true
);
$backendOptions = array('cache_dir' => $cache_dir);
$cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions);
if(!($cache_data = $cache->load($file_name))) {
$cache_data = new stdClass();
$cache_data = call_user_func_array(array($class, $function), array($param));
$cache->save($cache_data, $file_name);
}
//end
return $cache_data;
}
}