Issue #0001653: Caching WorldCheck searchlist and content data

This commit is contained in:
Aram HARUTYUNYAN 2013-09-26 06:14:00 +00:00
parent 0560448501
commit 0dad63915a
2 changed files with 46 additions and 23 deletions

View File

@ -44,15 +44,34 @@ class WorldcheckController extends Zend_Controller_Action
$summary = new stdClass(); $summary = new stdClass();
$summary->nameIdentifier = $nameIdentifier; $summary->nameIdentifier = $nameIdentifier;
$summary->matchType = 'WATCHLIST'; $summary->matchType = 'WATCHLIST';
//get results by lastName
$unfilteredWC = new stdClass();
$unfilteredWC = $wc->getSummariesArr($summary);
//end
$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
//check if display all results (search by lastName), or filtered results (search by fullName) //check if display all results (search by lastName), or filtered results (search by fullName)
$filtre = $request->getParam('filtre', 'tout'); $filtre = $request->getParam('filtre', 'tout');
$resultWC = $unfilteredWC; $resultWC = $unfilteredWC;
Zend_Registry::get('firebug')->info($resultWC);
if ($filtre=='filtered') if ($filtre=='filtered')
{ {
//get results by fullName (lastName and givenName) //get results by fullName (lastName and givenName)
@ -86,30 +105,15 @@ class WorldcheckController extends Zend_Controller_Action
$this->view->assign('filtres', $filtres); $this->view->assign('filtres', $filtres);
//end //end
$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);*/
//paginate results list //paginate results list
Zend_View_Helper_PaginationControl::setDefaultViewPartial('worldcheck/controls.phtml'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('worldcheck/controls.phtml');
$paginator = Zend_Paginator::factory($resultWC); $paginator = Zend_Paginator::factory($resultWC);
$this->view->paginator = $paginator; $this->view->paginator = $paginator;
$itemCount = $cacheConfig['page']['items']; $itemCount = $wcConfig['page']['items'];
$page = $this->_getParam('page', 1); $page = $this->_getParam('page', 1);
$ol_number = ($page-1)*$itemCount+1; $ol_number = ($page-1)*$itemCount+1;
/*if(!($cache->load('page_'.$page))) {
$cache->save($paginator, 'page_'.$page);
}*/
$paginator->setCurrentPageNumber($page); $paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($itemCount); $paginator->setItemCountPerPage($itemCount);
@ -157,7 +161,26 @@ class WorldcheckController extends Zend_Controller_Action
$param->nameType = $session->getNameType(); $param->nameType = $session->getNameType();
$wc = new WsWorldCheck(); $wc = new WsWorldCheck();
$content = $wc->getDetailsContent($param);
// 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);
}
$this->view->assign('matchIdentifier', $param->matchIdentifier); $this->view->assign('matchIdentifier', $param->matchIdentifier);
$this->view->assign('content', $content); $this->view->assign('content', $content);

View File

@ -10,4 +10,4 @@ wsworldcheck.response.start = 0
worldcheck.page.items = 15 worldcheck.page.items = 15
worldcheck.cachedir.path = ../data/cache/ worldcheck.cachedir.path = ../data/cache/
worldcheck.cachedir.name = worldcheck worldcheck.cachedir.name = worldcheck
worldcheck.cachedir.lifetime = 7200 worldcheck.cachedir.lifetime = 86400