mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 18:51:41 +09:00
Reformat cache handler code
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9814 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
9b4f219a0c
commit
518a8a2f59
1 changed files with 119 additions and 119 deletions
238
classes/cache/CacheHandler.class.php
vendored
238
classes/cache/CacheHandler.class.php
vendored
|
|
@ -1,130 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheHandler
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
* @brief Cache Handler
|
||||
* @version 0.1
|
||||
*
|
||||
**/
|
||||
/**
|
||||
* @class CacheHandler
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
* @brief Cache Handler
|
||||
* @version 0.1
|
||||
*
|
||||
**/
|
||||
|
||||
class CacheHandler extends Handler {
|
||||
class CacheHandler extends Handler {
|
||||
var $handler = null;
|
||||
var $keyGroupVersions = null;
|
||||
|
||||
var $handler = null;
|
||||
var $keyGroupVersions = null;
|
||||
|
||||
function &getInstance($target='object') {
|
||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$target]) {
|
||||
$GLOBALS['__XE_CACHE_HANDLER__'][$target] = new CacheHandler($target);
|
||||
}
|
||||
return $GLOBALS['__XE_CACHE_HANDLER__'][$target];
|
||||
function &getInstance($target='object') {
|
||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$target]) {
|
||||
$GLOBALS['__XE_CACHE_HANDLER__'][$target] = new CacheHandler($target);
|
||||
}
|
||||
return $GLOBALS['__XE_CACHE_HANDLER__'][$target];
|
||||
}
|
||||
|
||||
function CacheHandler($target, $info=null) {
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
if($target == 'object'){
|
||||
if($info->use_object_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_object_cache,0,8)=='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';
|
||||
$url = $info->use_template_cache;
|
||||
}
|
||||
function CacheHandler($target, $info=null) {
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
if($target == 'object'){
|
||||
if($info->use_object_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_object_cache,0,8)=='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';
|
||||
$url = $info->use_template_cache;
|
||||
}
|
||||
}
|
||||
|
||||
if($type){
|
||||
$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);
|
||||
}
|
||||
if($type){
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function get($key, $modified_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->get($key, $modified_time);
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
||||
function delete($key){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->delete($key);
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->isValid($key, $modified_time);
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
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;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
|
||||
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
|
||||
}
|
||||
|
||||
function invalidateGroupKey($keyGroupName){
|
||||
$this->keyGroupVersions[$keyGroupName]++;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
}
|
||||
|
||||
class CacheBase{
|
||||
function get($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
return false;
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
function isSupport(){
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function get($key, $modified_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->get($key, $modified_time);
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
||||
function delete($key){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->delete($key);
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->isValid($key, $modified_time);
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
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;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
|
||||
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
|
||||
}
|
||||
|
||||
function invalidateGroupKey($keyGroupName){
|
||||
$this->keyGroupVersions[$keyGroupName]++;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
}
|
||||
|
||||
class CacheBase{
|
||||
function get($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isValid($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSupport(){
|
||||
return false;
|
||||
}
|
||||
|
||||
function truncate(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file : CacheHandler.class.php */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue