Changed the way document search results are removed from cache - instead of delete, key incrementing is now used.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9500 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-10-05 15:16:52 +00:00
parent 484a2e8791
commit a69023da83
4 changed files with 62 additions and 92 deletions

View file

@ -8,7 +8,7 @@
**/
class CacheHandler extends Handler {
var $handler = null;
function &getInstance($target='object') {
@ -21,13 +21,13 @@
if($target == 'object'){
if($info->use_object_cache =='apc') $type = 'apc';
else if(substr($info->use_object_cache,0,8)=='memcache'){
$type = 'memcache';
$type = 'memcache';
$url = $info->use_object_cache;
}
}else if($target == 'template'){
if($info->use_template_cache =='apc') $type = 'apc';
else if(substr($info->use_template_cache,0,8)=='memcache'){
$type = 'memcache';
$type = 'memcache';
$url = $info->use_template_cache;
}
}
@ -69,9 +69,35 @@
if(!$this->handler) return false;
return $this->handler->truncate();
}
/**
* Function used for generating keys for similar objects.
*
* Ex: 1:document:123
* 1:document:777
*
* This allows easily removing all object of type "document"
* from cache by simply invalidating the group key.
*
* The new key will be 2:document:123, thus forcing the document
* to be reloaded from the database.
*/
function getGroupKey($keyGroupName, $key){
if(!$this->keyGroupVersions[$keyGroupName]){
$this->keyGroupVersions[$keyGroupName] = 1;
}
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
}
function invalidateGroupKey($keyGroupName){
$this->keyGroupVersions[$keyGroupName]++;
}
}
class CacheBase{
var $keyGroupVersions = array();
function get($key, $modified_time = 0){
return false;
}

View file

@ -35,7 +35,7 @@
$this->setMessage( sprintf(Context::getLang('msg_checked_document_is_deleted'), $document_count) );
}
/**
/**
* @brief change the module to move a specific article
**/
function moveDocumentModule($document_srl_list, $module_srl, $category_srl) {
@ -129,7 +129,7 @@
$oDB->rollback();
return $output;
}
// move the trackback
// move the trackback
$output = executeQuery('trackback.updateTrackbackModule', $args);
if(!$output->toBool()) {
$oDB->rollback();
@ -147,11 +147,11 @@
$oDB->rollback();
return $output;
}
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
foreach($document_srl_list as $document_srl)
{
@ -160,17 +160,12 @@
$cache_key_item = 'object_document_item:'.$document_srl;
$oCacheHandler->delete($cache_key_item);
}
$cache_object = $oCacheHandler->get('module_list_documents');
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$oCacheHandler->invalidateGroupKey('documentList');
}
return new Object();
}
/**
/**
* @brief Copy the post
**/
function copyDocumentModule($document_srl_list, $module_srl, $category_srl) {
@ -218,7 +213,7 @@
}
}
}
// Write a post
$output = $oDocumentController->insertDocument($obj, true);
if(!$output->toBool()) {
@ -296,7 +291,7 @@
}
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
foreach($document_srl_list as $document_srl)
{
@ -305,12 +300,7 @@
$cache_key_item = 'object_document_item:'.$document_srl;
$oCacheHandler->delete($cache_key_item);
}
$cache_object = $oCacheHandler->get('module_list_documents');
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$oCacheHandler->invalidateGroupKey('documentList');
}
return $output;
}
@ -431,7 +421,7 @@
$this->setMessage('success_deleted');
}
/**
* @brief control the order of extra variables
**/
@ -453,7 +443,7 @@
if($type == 'up') $new_idx = $var_idx-1;
else $new_idx = $var_idx+1;
if($new_idx<1) return new Object(-1,'msg_invalid_request');
$args->module_srl = $module_srl;
$args->var_idx = $new_idx;
$output = executeQuery('document.getDocumentExtraKeys', $args);
@ -499,12 +489,12 @@
function procDocumentAdminInsertAlias() {
$args = Context::gets('module_srl','document_srl', 'alias_title');
$alias_srl = Context::get('alias_srl');
if(!$alias_srl)
if(!$alias_srl)
{
$args->alias_srl = getNextSequence();
$query = "document.insertAlias";
}
else
else
{
$args->alias_srl = $alias_srl;
$query = "document.updateAlias";

View file

@ -243,16 +243,7 @@ class documentController extends document {
{
$cache_key = 'object:'.$obj->document_srl;
$oCacheHandler->delete($cache_key);
$cache_object = $oCacheHandler->get('module_list_documents');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$oCacheHandler->invalidateGroupKey('documentList');
}
return $output;
@ -414,16 +405,7 @@ class documentController extends document {
{
$cache_key = 'object:'.$obj->document_srl;
$oCacheHandler->delete($cache_key);
$cache_object = $oCacheHandler->get('module_list_documents');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$oCacheHandler->invalidateGroupKey('documentList');
//remove document item from cache
$cache_key = 'object_document_item:'.$obj->document_srl;
$oCacheHandler->delete($cache_key);
@ -507,19 +489,10 @@ class documentController extends document {
{
$cache_key = 'object:'.$document_srl;
$oCacheHandler->delete($cache_key);
$cache_object = $oCacheHandler->get('module_list_documents');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$cache_key = 'object_document_item:'.$document_srl;
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->invalidateGroupKey('documentList');
$cache_key = 'object_document_item:'.$document_srl;
$oCacheHandler->delete($cache_key);
}
return $output;
}
@ -901,16 +874,7 @@ class documentController extends document {
{
$cache_key = 'object:'.$document_srl;
$oCacheHandler->delete($cache_key);
$cache_object = $oCacheHandler->get('module_list_documents');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key_object = $object;
$oCacheHandler->delete($cache_key_object);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key_object);
}
$oCacheHandler->delete('module_list_documents');
$oCacheHandler->invalidateGroupKey('documentList');
//remove document item from cache
$cache_key = 'object_document_item:'.$document_srl;
$oCacheHandler->delete($cache_key);

View file

@ -41,8 +41,8 @@
if($output->toBool() && $output->data) {
foreach($output->data as $key => $val) {
if(!isset($val->value)) continue;
if(!$extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0]) $extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0] = trim($val->value);
$extra_vars[$val->document_srl][$val->var_idx][$val->lang_code] = trim($val->value);
if(!$extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0]) $extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0] = trim($val->value);
$extra_vars[$val->document_srl][$val->var_idx][$val->lang_code] = trim($val->value);
}
}
@ -76,8 +76,8 @@
if($vars[-1][$user_lang_code]) $GLOBALS['XE_DOCUMENT_LIST'][$document_srl]->add('title',$vars[-1][$user_lang_code]);
// Information processing
if($vars[-2][$user_lang_code]) $GLOBALS['XE_DOCUMENT_LIST'][$document_srl]->add('content',$vars[-2][$user_lang_code]);
if($vars[-1][$user_lang_code] || $vars[-2][$user_lang_code]){
if($vars[-1][$user_lang_code] || $vars[-2][$user_lang_code]){
unset($checked_documents[$document_srl]);
}
@ -155,22 +155,12 @@
// cache controll
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$obj->module_srl.'_category_srl:'.$obj->category_srl.'_list_count:'.$obj->list_count.'_search_target:'.$obj->search_target.'_search_keyword:'.$obj->search_keyword.'_page'.$obj->page;
$output = $oCacheHandler->get($cache_key);
$cache_object = $oCacheHandler->get('module_list_documents');
if($cache_object) {
if(!in_array($cache_key, $cache_object)) {
$cache_object[]=$cache_key;
$oCacheHandler->put('module_list_documents',$cache_object);
}
} else {
$cache_object = array();
$cache_object[] = $cache_key;
$oCacheHandler->put('module_list_documents',$cache_object);
}
$object_key = 'object:'.$obj->module_srl.'_category_srl:'.$obj->category_srl.'_list_count:'.$obj->list_count.'_search_target:'.$obj->search_target.'_search_keyword:'.$obj->search_keyword.'_page'.$obj->page;
$cache_key = $oCacheHandler->getGroupKey('documentList', $object_key);
$output = $oCacheHandler->get($cache_key);
}
if(!$output){
$logged_info = Context::get('logged_info');
$sort_check = $this->_setSortIndex($obj, $load_extra_vars);
@ -334,7 +324,7 @@
} else {
$output = executeQueryArray($query_id, $args, $columnList);
}
}
}
// Return if no result or an error occurs
if(!$output->toBool()||!count($output->data)) return $output;
@ -823,7 +813,7 @@
// Bringing existing extra_keys
$extra_keys = $this->getExtraKeys($module_srl);
Context::set('extra_keys', $extra_keys);
$security = new Security();
$security = new Security();
$security->encodeHTML('extra_keys..name','extra_keys..eid');
// Get information of module_grants
@ -885,8 +875,8 @@
$category_info->title = htmlspecialchars($category_info->title);
Context::set('category_info', $category_info);
$security = new Security();
$security = new Security();
$security->encodeHTML('group_list..title');
// tpl template file directly compile and will return a variable and puts it on.
@ -1067,7 +1057,7 @@
{
$sortIndex = $obj->sort_index;
$isExtraVars = false;
if(!in_array($sortIndex, array('list_order','regdate','last_update','update_order','readed_count','voted_count','comment_count','trackback_count','uploaded_count','title','category_srl')))
if(!in_array($sortIndex, array('list_order','regdate','last_update','update_order','readed_count','voted_count','comment_count','trackback_count','uploaded_count','title','category_srl')))
{
// get module_srl extra_vars list
if ($load_extra_vars)