Changed the way comment lists 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@9501 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2011-10-05 16:12:42 +00:00
parent a69023da83
commit 441ef79f1b
4 changed files with 51 additions and 101 deletions

View file

@ -10,10 +10,11 @@
class CacheHandler extends Handler {
var $handler = null;
var $keyGroupVersions = null;
function &getInstance($target='object') {
return new CacheHandler($target);
}
function &getInstance($target='object') {
return new CacheHandler($target);
}
function CacheHandler($target, $info=null) {
if(!$info) $info = Context::getDBInfo();
@ -36,6 +37,11 @@
$class = 'Cache' . ucfirst($type);
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
$this->handler = call_user_func(array($class,'getInstance'), $url);
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
if(!$this->keyGroupVersions) {
$this->keyGroupVersions = array();
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
}
}
}
}
@ -69,7 +75,7 @@
if(!$this->handler) return false;
return $this->handler->truncate();
}
/**
* Function used for generating keys for similar objects.
*
@ -85,6 +91,7 @@
function getGroupKey($keyGroupName, $key){
if(!$this->keyGroupVersions[$keyGroupName]){
$this->keyGroupVersions[$keyGroupName] = 1;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
}
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
@ -92,12 +99,11 @@
function invalidateGroupKey($keyGroupName){
$this->keyGroupVersions[$keyGroupName]++;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
}
}
class CacheBase{
var $keyGroupVersions = array();
function get($key, $modified_time = 0){
return false;
}

View file

@ -78,17 +78,12 @@
}
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_object = $oCacheHandler->get('comment_list_document_pages');
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
$msgCode = '';
@ -176,14 +171,9 @@
$output = executeQuery('comment.deleteModuleCommentsList', $args);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_object = $oCacheHandler->get('comment_list_document_pages');
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
return $output;
}

View file

@ -2,7 +2,7 @@
/**
* @class commentController
* @author NHN (developers@xpressengine.com)
* @brief controller class of the comment module
* @brief controller class of the comment module
**/
class commentController extends comment {
@ -242,20 +242,11 @@
$output->add('comment_srl', $obj->comment_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_key_newest = 'object_newest_comment_list:'.$obj->module_srl;
$oCacheHandler->delete($cache_key_newest);
$cache_object = $oCacheHandler->get('comment_list_document_pages');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
return $output;
}
@ -335,20 +326,11 @@
$output->add('comment_srl', $obj->comment_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_key_newest = 'object_newest_comment_list:'.$obj->module_srl;
$oCacheHandler->delete($cache_key_newest);
$cache_object = $oCacheHandler->get('comment_list_document_pages');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
return $output;
}
@ -388,7 +370,7 @@
$comment_count = $oCommentModel->getCommentCount($document_srl);
// create the controller object of the document
$oDocumentController = &getController('document');
// update comment count of the article posting
// update comment count of the article posting
$output = $oDocumentController->updateCommentCount($document_srl, $comment_count, null, false);
if(!$output->toBool()) {
$oDB->rollback();
@ -415,18 +397,9 @@
$output->add('document_srl', $document_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_object = $oCacheHandler->get('comment_list_document_pages');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
return $output;
}
@ -483,18 +456,9 @@
}
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
if($oCacheHandler->isSupport())
{
$cache_object = $oCacheHandler->get('comment_list_document_pages');
if(isset($cache_object) && is_array($cache_object)){
foreach ($cache_object as $object){
$cache_key = $object;
$oCacheHandler->delete($cache_key);
}
}elseif(!is_array($cache_object)) {
$oCacheHandler->delete($cache_key);
}
$oCacheHandler->delete('comment_list_document_pages');
$oCacheHandler->invalidateGroupKey('commentList');
}
return $output;
@ -533,7 +497,7 @@
$success_message = 'success_blamed';
}
// invalid vote if vote info exists in the session info.
// invalid vote if vote info exists in the session info.
if($_SESSION['voted_comment'][$comment_srl]) return new Object(-1, $failed_voted);
$oCommentModel = &getModel('comment');
@ -543,18 +507,18 @@
$_SESSION['voted_comment'][$comment_srl] = true;
return new Object(-1, $failed_voted);
}
// if the comment author is a member
// if the comment author is a member
if($oComment->get('member_srl')) {
// create the member model object
$oMemberModel = &getModel('member');
$member_srl = $oMemberModel->getLoggedMemberSrl();
// session registered if the author information matches to the current logged-in user's.
// session registered if the author information matches to the current logged-in user's.
if($member_srl && $member_srl == $oComment->get('member_srl')) {
$_SESSION['voted_comment'][$comment_srl] = true;
return new Object(-1, $failed_voted);
}
}
// If logged-in, use the member_srl. otherwise use the ipaddress.
// If logged-in, use the member_srl. otherwise use the ipaddress.
if($member_srl) {
$args->member_srl = $member_srl;
} else {
@ -562,7 +526,7 @@
}
$args->comment_srl = $comment_srl;
$output = executeQuery('comment.getCommentVotedLogInfo', $args);
// session registered if log info contains recommendation vote log.
// session registered if log info contains recommendation vote log.
if($output->data->count) {
$_SESSION['voted_comment'][$comment_srl] = true;
return new Object(-1, $failed_voted);
@ -596,7 +560,7 @@
$args->comment_srl = $comment_srl;
$output = executeQuery('comment.getDeclaredComment', $args);
if(!$output->toBool()) return $output;
// get the original comment
// get the original comment
$oCommentModel = &getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl, false, false);
// failed if both ip addresses between author's and the current user are same.
@ -604,9 +568,9 @@
$_SESSION['declared_comment'][$comment_srl] = true;
return new Object(-1, 'failed_declared');
}
// if the comment author is a member
// if the comment author is a member
if($oComment->get('member_srl')) {
// create the member model object
// create the member model object
$oMemberModel = &getModel('member');
$member_srl = $oMemberModel->getLoggedMemberSrl();
// session registered if the author information matches to the current logged-in user's.
@ -628,7 +592,7 @@
$_SESSION['declared_comment'][$comment_srl] = true;
return new Object(-1, 'failed_declared');
}
// execute insert
// execute insert
if($output->data->declared_count > 0) $output = executeQuery('comment.updateDeclaredComment', $args);
else $output = executeQuery('comment.insertDeclaredComment', $args);
if(!$output->toBool()) return $output;
@ -657,7 +621,7 @@
}
/**
* @brief save the comment extension form for each module
* @brief save the comment extension form for each module
**/
function procCommentInsertModuleConfig() {
$module_srl = Context::get('target_module_srl');

View file

@ -24,7 +24,7 @@
$mid = Context::get('cur_mid');
$logged_info = Context::get('logged_info');
$act = Context::get('cur_act');
// array values for menu_list, "comment post, target, url"
$menu_list = array();
// call a trigger
@ -59,7 +59,7 @@
}
// call a trigger (after)
ModuleHandler::triggerCall('comment.getCommentMenu', 'after', $menu_list);
// find a comment by IP matching if an administrator.
// find a comment by IP matching if an administrator.
if($logged_info->is_admin == 'Y') {
$oCommentModel = &getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl);
@ -168,12 +168,12 @@
$args->module_srl = $module_srl;
$output = executeQuery('comment.getCommentCount', $args);
$total_count = $output->data->count;
return (int)$total_count;
}
/**
/**
* @brief get the comment in corresponding with mid.
**/
function getNewestCommentList($obj, $columnList = array()) {
@ -182,7 +182,7 @@
$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
unset($obj->mid);
}
// check if module_srl is an arrary.
// check if module_srl is an arrary.
if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
else $args->module_srl = $obj->module_srl;
$args->list_count = $obj->list_count;
@ -197,7 +197,7 @@
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
if(!$output->toBool()) return $output;
$comment_list = $output->data;
if($comment_list) {
if(!is_array($comment_list)) $comment_list = array($comment_list);
@ -215,26 +215,16 @@
return $result;
}
/**
/**
* @brief get a comment list of the doc in corresponding woth document_srl.
**/
function getCommentList($document_srl, $page = 0, $is_admin = false, $count = 0) {
// cache controll
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$document_srl.'_'.$page;
$object_key = 'object:'.$document_srl.'_'.$page.'_'.($is_admin ? 'Y' : 'N') .'_' . $count;
$cache_key = $oCacheHandler->getGroupKey('commentList', $object_key);
$output = $oCacheHandler->get($cache_key);
$cache_object = $oCacheHandler->get('comment_list_document_pages');
if($cache_object) {
if(!in_array($cache_key, $cache_object)) {
$cache_object[]=$cache_key;
$oCacheHandler->put('comment_list_document_pages',$cache_object);
}
} else {
$cache_object = array();
$cache_object[] = $cache_key;
$oCacheHandler->put('comment_list_document_pages',$cache_object);
}
}
if(!$output){
// get the number of comments on the document module
@ -247,7 +237,7 @@
if($oDocument->getCommentCount()<1) return;
// get a list of comments
$module_srl = $oDocument->get('module_srl');
if(!$count) {
$comment_config = $this->getCommentConfig($module_srl);
$comment_count = $comment_config->comment_count;
@ -256,7 +246,7 @@
$comment_count = $count;
}
// get a very last page if no page exists
if(!$page) $page = (int)( ($oDocument->getCommentCount()-1) / $comment_count) + 1;
if(!$page) $page = (int)( ($oDocument->getCommentCount()-1) / $comment_count) + 1;
// get a list of comments
$args->document_srl = $document_srl;
$args->list_count = $comment_count;
@ -273,12 +263,12 @@
}
//insert in cache
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
return $output;
}
/**
* @brief update a list of comments in corresponding with document_srl
* take care of previously used data than GA version