Caching implementation for objects

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8745 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
dragan-dan 2011-08-10 17:47:59 +00:00
parent 1b47a294d3
commit 70a69ff4fe
18 changed files with 709 additions and 322 deletions

View file

@ -62,7 +62,7 @@
}
function delete($key) {
$this->_delete(md5(_XE_PATH_.$key));
$this->_delete($key);
}
function truncate() {

View file

@ -51,7 +51,7 @@
}
$truncated = array();
$oObjectCacheHandler = &CacheHandler::getInstance();
$oObjectCacheHandler = &CacheHandler::getInstance('object');
$oTemplateCacheHandler = &CacheHandler::getInstance('template');
if($oObjectCacheHandler->isSupport()){

View file

@ -79,6 +79,18 @@
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
$this->setMessage( sprintf(Context::getLang('msg_checked_comment_is_deleted'), $deleted_count) );
if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON'))) {
@ -158,6 +170,17 @@
if(!$output->toBool()) return $output;
$output = executeQuery('comment.deleteModuleCommentsList', $args);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
return $output;
}

View file

@ -240,6 +240,17 @@
$output->add('comment_srl', $obj->comment_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
return $output;
}
@ -316,6 +327,17 @@
$oDB->commit();
$output->add('comment_srl', $obj->comment_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
return $output;
}
@ -379,6 +401,17 @@
$oDB->commit();
$output->add('document_srl', $document_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
return $output;
}
@ -431,6 +464,17 @@
$this->_deleteDeclaredComments($args);
$this->_deleteVotedComments($args);
}
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
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');
}
return $output;
}

View file

@ -200,6 +200,24 @@
* @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;
$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
$oDocumentModel = &getModel('document');
$columnList = array('document_srl', 'module_srl', 'comment_count');
@ -234,6 +252,10 @@
$output = executeQueryArray('comment.getCommentPageList', $args);
if(!$output->toBool()) return;
}
//insert in cache
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
return $output;
}

View file

@ -149,6 +149,22 @@
}
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
foreach($document_srl_list as $document_srl)
{
$cache_key = 'object:'.$document_srl;
$oCacheHandler->delete($cache_key);
}
$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');
}
return new Object();
}
@ -266,7 +282,30 @@
**/
function deleteModuleDocument($module_srl) {
$args->module_srl = $module_srl;
$oDocumentModel = &getModel('document');
$args->module_srl = $module_srl;
$document_list = $oDocumentModel->getDocumentList($args);
$documents = $document_list->data;
$output = executeQuery('document.deleteModuleDocument', $args);
foreach ($documents as $oDocument){
$document_srl_list[] = $oDocument->document_srl;
}
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
foreach($document_srl_list as $document_srl)
{
$cache_key = 'object:'.$document_srl;
$oCacheHandler->delete($cache_key);
}
$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');
}
return $output;
}

View file

@ -237,6 +237,20 @@ class documentController extends document {
$this->addGrant($obj->document_srl);
$output->add('document_srl',$obj->document_srl);
$output->add('category_srl',$obj->category_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$obj->document_srl;
$oCacheHandler->delete($cache_key);
$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');
}
return $output;
}
@ -390,6 +404,20 @@ class documentController extends document {
FileHandler::removeDir(sprintf('files/cache/thumbnails/%s',getNumberingPath($obj->document_srl, 3)));
$output->add('document_srl',$obj->document_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$obj->document_srl;
$oCacheHandler->delete($cache_key);
$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');
}
return $output;
}
@ -460,6 +488,20 @@ class documentController extends document {
// commit
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$document_srl;
$oCacheHandler->delete($cache_key);
$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');
}
return $output;
}

View file

@ -152,6 +152,25 @@
* @brief module_srl value, bringing the list of documents
**/
function getDocumentList($obj, $except_notice = false, $load_extra_vars=true, $columnList = array()) {
// 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.'_documents';
$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);
}
}
if(!$output){
$logged_info = Context::get('logged_info');
$sort_check = $this->_setSortIndex($obj, $load_extra_vars);
@ -349,6 +368,9 @@
$output->data[$number] = $GLOBALS['XE_DOCUMENT_LIST'][$document->document_srl];
}
}
//insert in cache
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
return $output;
}

View file

@ -187,6 +187,13 @@
$oLayoutModel = &getModel('layout');
$cache_file = $oLayoutModel->getUserLayoutCache($args->layout_srl, Context::getLangType());
FileHandler::removeFile($cache_file);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$args->layout_srl;
$oCacheHandler->delete($cache_key);
}
}
return $output;
}
@ -211,6 +218,13 @@
// Delete Layout
$args->layout_srl = $layout_srl;
$output = executeQuery("layout.deleteLayout", $args);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$layout_srl;
$oCacheHandler->delete($cache_key);
}
if(!$output->toBool()) return $output;
return new Object(0,'success_deleted');

View file

@ -37,13 +37,24 @@
* Return DB info + XML info of the generated layout
**/
function getLayout($layout_srl) {
// cache controll
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$layout_srl;
$layout_info = $oCacheHandler->get($cache_key);
}
if(!$layout_info) {
// Get information from the DB
$args->layout_srl = $layout_srl;
$output = executeQuery('layout.getLayout', $args);
if(!$output->data) return;
// Return xml file informaton after listing up the layout and extra_vars
$layout_info = $this->getLayoutInfo($layout, $output->data, $output->data->layout_type);
//insert in cache
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$layout_info);
}
return $layout_info;
}
/**

View file

@ -1698,7 +1698,12 @@
$oDB->commit();
// Save Session
if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$args->member_srl;
$oCacheHandler->delete($cache_key);
}
$logged_info = Context::get('logged_info');
$output->add('member_srl', $args->member_srl);
@ -1710,6 +1715,12 @@
**/
function updateMemberPassword($args) {
$output = executeQuery('member.updateChangePasswordDate', $args);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$args->member_srl;
$oCacheHandler->delete($cache_key);
}
$args->password = md5($args->password);
return executeQuery('member.updateMemberPassword', $args);
}

View file

@ -182,11 +182,21 @@
//columnList size zero... get full member info
if(!$GLOBALS['__member_info__'][$member_srl] || count($columnList) == 0) {
//if(true) {
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$member_srl;
$output = $oCacheHandler->get($cache_key);
}
if(!$output){
$args->member_srl = $member_srl;
$output = executeQuery('member.getMemberInfoByMemberSrl', $args, $columnList);
if(!$output->data) return;
//insert in cache
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
$this->arrangeMemberInfo($output->data, $site_srl);
}
return $GLOBALS['__member_info__'][$member_srl];

View file

@ -295,6 +295,12 @@
// Register
$oModuleController->insertModuleSkinVars($module_srl, $obj);
}
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$module_srl;
$oCacheHandler->delete($cache_key);
}
$this->setLayoutPath('./common/tpl');
$this->setLayoutFile('default_layout.html');

View file

@ -196,6 +196,12 @@
}
$output = executeQuery('module.updateSite', $args);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.'default_mid';
$oCacheHandler->delete($cache_key);
}
return $output;
}
@ -309,6 +315,14 @@
$oDB->commit();
$output->add('module_srl',$args->module_srl);
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$args->module_srl;
$oCacheHandler->delete($cache_key);
$cache_key = 'object:'.$args->mid;
$oCacheHandler->delete($cache_key);
}
return $output;
}
@ -364,7 +378,14 @@
// commit
$oDB->commit();
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$args->module_srl;
$oCacheHandler->delete($cache_key);
$cache_key = 'object:'.$args->mid;
$oCacheHandler->delete($cache_key);
}
return $output;
}
@ -386,6 +407,12 @@
**/
function clearDefaultModule() {
$output = executeQuery('module.clearDefaultModule');
//remove from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.'default_mid';
$oCacheHandler->delete($cache_key);
}
if(!$output->toBool()) return $output;
return $output;

View file

@ -68,6 +68,12 @@
* @brief Get the defaul mid according to the domain
**/
function getDefaultMid() {
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.'default_mid';
$output = $oCacheHandler->get($cache_key);
}
if(!$output){
$default_url = preg_replace('/\/$/','',Context::getDefaultUrl());
$request_url = preg_replace('/\/$/','',Context::getRequestUri());
$vid = Context::get('vid');
@ -122,6 +128,8 @@
$output = executeQuery('module.getSiteInfo', $args);
}
}
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
$module_info = $output->data;
if(!$module_info->module_srl) return $module_info;
if(is_array($module_info) && $module_info->data[0]) $module_info = $module_info[0];
@ -134,7 +142,23 @@
function getModuleInfoByMid($mid, $site_srl = 0, $columnList = array()) {
$args->mid = $mid;
$args->site_srl = (int)$site_srl;
$output = executeQuery('module.getMidInfo', $args, $columnList);
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$mid;
$module_srl = $oCacheHandler->get($cache_key);
if($module_srl){
$cache_key = 'object:'.$module_srl;
$output = $oCacheHandler->get($cache_key);
}
}
if(!$output){
$output = executeQuery('module.getMidInfo', $args);
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$mid;
$oCacheHandler->put($cache_key,$output->data->module_srl);
}
}
$module_info = $output->data;
if(!$module_info->module_srl && $module_info->data[0]) $module_info = $module_info->data[0];
return $this->addModuleExtraVars($module_info);
@ -146,10 +170,24 @@
function getModuleInfoByModuleSrl($module_srl, $columnList = array()) {
// Get data
$args->module_srl = $module_srl;
$output = executeQuery('module.getMidInfo', $args, $columnList);
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$module_srl;
$output = $oCacheHandler->get($cache_key);
}
if(!$output){
$output = executeQuery('module.getMidInfo', $args );
if(!$output->data) return;
$module_info = $this->addModuleExtraVars($output->data);
return $module_info;
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key,$output);
}
if(count($columnList)){
foreach ($output->data as $key => $item) {
if (in_array($key, $columnList)){
$module_info->$key = $item;
}
}
} else $module_info = $output->data;
return $this->addModuleExtraVars($module_info);
}
/**

View file

@ -0,0 +1,12 @@
<query id="getExpiredSession" action="select">
<tables>
<table name="session" />
</tables>
<columns>
<column name="session_key" />
</columns>
<conditions>
<condition operation="less" column="expired" default="curdate()" notnull="notnull" />
</conditions>
</query>

View file

@ -23,11 +23,21 @@
function write($session_key, $val) {
if(!$session_key || !$this->session_started) return;
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$cache_vars = $oCacheHandler->get($cache_key);
}
$args->session_key = $session_key;
if($cache_vars) $session_info = $cache_vars;
else {
$output = executeQuery('session.getSession', $args);
$session_info = $output->data;
}
//if ip has changed delete the session from cache and db
if($session_info->session_key == $session_key && $session_info->ipaddress != $_SERVER['REMOTE_ADDR']) {
if($oCacheHandler->isSupport()) $oCacheHandler->delete($cache_key);
executeQuery('session.deleteSession', $args);
return true;
}
@ -46,16 +56,53 @@
} else {
$args->member_srl = 0;
}
$args->ipaddress = $_SERVER['REMOTE_ADDR'];
$args->last_update = date("YmdHis", time());
$diff = $args->last_update - $cache_vars->last_update;
//verify if session values have changed
if($val == $cache_vars->val){
// if more than 5 minutes passed than modify the db session also
if($diff > 300){
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
}
else {
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
}
}
else {
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
else $output = executeQuery('session.insertSession', $args);
}
return true;
}
function destroy($session_key) {
if(!$session_key || !$this->session_started) return;
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
//remove session from db
$args->session_key = $session_key;
executeQuery('session.deleteSession', $args);
return true;
@ -63,6 +110,17 @@
function gc($maxlifetime) {
if(!$this->session_started) return;
$expired_sessions = executeQueryArray('session.getExpiredSessions');
if($expired_session){
foreach ($expired_sessions as $session_key){
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
}
}
executeQuery('session.gcSession');
return true;
}

View file

@ -20,6 +20,13 @@
function read($session_key) {
if(!$session_key || !$this->session_started) return;
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$session_key;
$output->data = $oCacheHandler->get($cache_key);
}
if(!$output->data) {
$args->session_key = $session_key;
$columnList = array('session_key', 'cur_mid', 'val');
$output = executeQuery('session.getSession', $args, $columnList);
@ -36,6 +43,7 @@
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
}
}
return $output->data->val;
}