mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-30 15:52:17 +09:00
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:
parent
1b47a294d3
commit
70a69ff4fe
18 changed files with 709 additions and 322 deletions
12
modules/session/queries/getExpiredSessions.xml
Normal file
12
modules/session/queries/getExpiredSessions.xml
Normal 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>
|
||||
|
||||
|
|
@ -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;
|
||||
$output = executeQuery('session.getSession', $args);
|
||||
$session_info = $output->data;
|
||||
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;
|
||||
}
|
||||
|
||||
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
|
||||
else $output = executeQuery('session.insertSession', $args);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,23 +19,31 @@
|
|||
|
||||
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);
|
||||
// Confirm there is a table created if read error occurs
|
||||
if(!$output->toBool()) {
|
||||
$oDB = &DB::getInstance();
|
||||
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
|
||||
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
|
||||
$output = executeQuery('session.getSession', $args);
|
||||
}
|
||||
// Check if there is a table created in case there is no "cur_mid" value in the sessions information
|
||||
if(!isset($output->data->cur_mid)) {
|
||||
$oDB = &DB::getInstance();
|
||||
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
|
||||
}
|
||||
|
||||
$args->session_key = $session_key;
|
||||
$columnList = array('session_key', 'cur_mid', 'val');
|
||||
$output = executeQuery('session.getSession', $args, $columnList);
|
||||
// Confirm there is a table created if read error occurs
|
||||
if(!$output->toBool()) {
|
||||
$oDB = &DB::getInstance();
|
||||
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
|
||||
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
|
||||
$output = executeQuery('session.getSession', $args);
|
||||
}
|
||||
// Check if there is a table created in case there is no "cur_mid" value in the sessions information
|
||||
if(!isset($output->data->cur_mid)) {
|
||||
$oDB = &DB::getInstance();
|
||||
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
|
||||
}
|
||||
|
||||
}
|
||||
return $output->data->val;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue