mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 18:51:41 +09:00
adds comments for phpDoc
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10727 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
6aa08760e5
commit
e425c80720
5 changed files with 424 additions and 20 deletions
69
classes/cache/CacheApc.class.php
vendored
69
classes/cache/CacheApc.class.php
vendored
|
|
@ -1,14 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheApc
|
||||
* Cache class for APC
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
* @brief APC Handler
|
||||
* @version 0.1
|
||||
**/
|
||||
|
||||
class CacheApc extends CacheBase {
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
*/
|
||||
var $valid_time = 36000;
|
||||
|
||||
/**
|
||||
* Get instance of CacheApc
|
||||
*
|
||||
* @param void $opt Not used
|
||||
* @return CacheApc instance of CacheApc
|
||||
*/
|
||||
function getInstance($opt=null){
|
||||
if(!$GLOBALS['__CacheApc__']) {
|
||||
$GLOBALS['__CacheApc__'] = new CacheApc();
|
||||
|
|
@ -16,18 +24,46 @@ class CacheApc extends CacheBase {
|
|||
return $GLOBALS['__CacheApc__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheApc(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
return function_exists('apc_add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a variable in the data store
|
||||
*
|
||||
* @param string $key Store the variable using this name. $key are cache-unique, so storing a second value with the same $key will overwrite the original value.
|
||||
* @param mixed $buff The variable to store
|
||||
* @param int $valid_time Time To Live; store $buff in the cache for ttl seconds.
|
||||
* After the ttl has passed., the stored variable will be expunged from the cache (on the next request).
|
||||
* If no ttl is supplied, use the default valid time CacheApc::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
|
|
@ -42,6 +78,14 @@ class CacheApc extends CacheBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a stored variable from the cache
|
||||
*
|
||||
* @param string $key The $key used to store the value.
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
|
|
@ -55,15 +99,32 @@ class CacheApc extends CacheBase {
|
|||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache(private)
|
||||
*
|
||||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
$this->put($_key,null,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
|
|
|
|||
77
classes/cache/CacheFile.class.php
vendored
77
classes/cache/CacheFile.class.php
vendored
|
|
@ -1,15 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheFile
|
||||
* Cache class for file
|
||||
*
|
||||
* Filedisk Cache Handler
|
||||
*
|
||||
* @author Arnia Software (xe_dev@arnia.ro)
|
||||
* @brief Filedisk Cache Handler
|
||||
* @version 0.1
|
||||
**/
|
||||
|
||||
class CacheFile extends CacheBase {
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
*/
|
||||
var $valid_time = 36000;
|
||||
|
||||
/**
|
||||
* Path that value to stored
|
||||
* @var string
|
||||
*/
|
||||
var $cache_dir = 'files/cache/store/';
|
||||
|
||||
/**
|
||||
* Get instance of CacheFile
|
||||
*
|
||||
* @return CacheFile instance of CacheFile
|
||||
*/
|
||||
function getInstance(){
|
||||
if(!$GLOBALS['__CacheFile__']) {
|
||||
$GLOBALS['__CacheFile__'] = new CacheFile();
|
||||
|
|
@ -17,25 +31,56 @@ class CacheFile extends CacheBase {
|
|||
return $GLOBALS['__CacheFile__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheFile(){
|
||||
$this->cache_dir = _XE_PATH_ . $this->cache_dir;
|
||||
if(!is_dir($this->cache_dir)) FileHandler::makeDir($this->cache_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name by key
|
||||
*
|
||||
* @param string $key The key that will be associated with the item.
|
||||
* @return string Returns cache file path
|
||||
*/
|
||||
private function getCacheFileName($key){
|
||||
return $this->cache_dir . str_replace(':', '_', $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
function isSupport(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a variable in the data store
|
||||
*
|
||||
* @param string $key Store the variable using this name.
|
||||
* @param mixed $obj The variable to store
|
||||
* @param int $valid_time Not used
|
||||
* @return void
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$text = serialize($obj);
|
||||
FileHandler::writeFile($cache_file, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Not used
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
if(file_exists($cache_file)) return true;
|
||||
|
|
@ -43,6 +88,13 @@ class CacheFile extends CacheBase {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a stored variable from the cache
|
||||
*
|
||||
* @param string $key The $key used to store the value.
|
||||
* @param int $modified_time Not used
|
||||
* @return false|mixed Return false on failure. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0) {
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$content = FileHandler::readFile($cache_file);
|
||||
|
|
@ -51,15 +103,32 @@ class CacheFile extends CacheBase {
|
|||
return unserialize($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache(private)
|
||||
*
|
||||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
$cache_file = $this->getCacheFileName($_key);
|
||||
FileHandler::removeFile($cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
$this->_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
FileHandler::removeFilesInDir($this->cache_dir);
|
||||
}
|
||||
|
|
|
|||
128
classes/cache/CacheHandler.class.php
vendored
128
classes/cache/CacheHandler.class.php
vendored
|
|
@ -1,15 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheHandler
|
||||
* CacheHandler
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
* @brief Cache Handler
|
||||
* @version 0.1
|
||||
**/
|
||||
|
||||
class CacheHandler extends Handler {
|
||||
/**
|
||||
* instance of cache handler
|
||||
* @var CacheBase
|
||||
*/
|
||||
var $handler = null;
|
||||
|
||||
/**
|
||||
* Version of key group
|
||||
* @var int
|
||||
*/
|
||||
var $keyGroupVersions = null;
|
||||
|
||||
/**
|
||||
* Get a instance of CacheHandler(for singleton)
|
||||
*
|
||||
* @param string $target type of cache (object|template)
|
||||
* @param object $info info. of DB
|
||||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
function &getInstance($target = 'object', $info = null, $always_use_file = false) {
|
||||
$cache_handler_key = $target . ($always_use_file ? '_file' : '');
|
||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key]) {
|
||||
|
|
@ -18,6 +33,17 @@ class CacheHandler extends Handler {
|
|||
return $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Do not use this directly. You can use getInstance() instead.
|
||||
*
|
||||
* @see CacheHandler::getInstance
|
||||
* @param string $target type of cache (object|template)
|
||||
* @param object $info info. of DB
|
||||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
function CacheHandler($target, $info = null, $always_use_file = false) {
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
|
|
@ -50,31 +76,73 @@ class CacheHandler extends Handler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached data
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->get($key, $modified_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data into cache
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param mixed $obj Value of a variable to store. $value supports all data types except resources, such as file handlers.
|
||||
* @param int $valid_time Time for the variable to live in the cache in seconds.
|
||||
* After the value specified in ttl has passed the stored variable will be deleted from the cache.
|
||||
* If no ttl is supplied, use the default valid time.
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Cache
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @return void
|
||||
*/
|
||||
function delete($key){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->isValid($key, $modified_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all cache
|
||||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function truncate(){
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->truncate();
|
||||
|
|
@ -91,6 +159,10 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* The new key will be 2:document:123, thus forcing the document
|
||||
* to be reloaded from the database.
|
||||
*
|
||||
* @param string $keyGroupName Group name
|
||||
* @param string $key Cache key
|
||||
* @return string
|
||||
*/
|
||||
function getGroupKey($keyGroupName, $key){
|
||||
if(!$this->keyGroupVersions[$keyGroupName]){
|
||||
|
|
@ -101,29 +173,77 @@ class CacheHandler extends Handler {
|
|||
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make invalid group key (like delete group key)
|
||||
*
|
||||
* @param string $keyGroupName Group name
|
||||
* @return void
|
||||
*/
|
||||
function invalidateGroupKey($keyGroupName){
|
||||
$this->keyGroupVersions[$keyGroupName]++;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class of Cache
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheBase{
|
||||
|
||||
/**
|
||||
* Get cached data
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data into cache
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param mixed $obj Value of a variable to store. $value supports all data types except resources, such as file handlers.
|
||||
* @param int $valid_time Time for the variable to live in the cache in seconds.
|
||||
* After the value specified in ttl has passed the stored variable will be deleted from the cache.
|
||||
* If no ttl is supplied, use the default valid time.
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all cache
|
||||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function truncate(){
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
98
classes/cache/CacheMemcache.class.php
vendored
98
classes/cache/CacheMemcache.class.php
vendored
|
|
@ -1,15 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheMemcache
|
||||
* Cache class for memcache
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
* @brief Memcache Handler
|
||||
* @version 0.1
|
||||
**/
|
||||
|
||||
class CacheMemcache extends CacheBase {
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
*/
|
||||
var $valid_time = 36000;
|
||||
|
||||
/**
|
||||
* instance of Memcahe
|
||||
* @var Memcahe
|
||||
*/
|
||||
var $Memcache;
|
||||
|
||||
/**
|
||||
* Get instance of CacheMemcache
|
||||
*
|
||||
* @param string $url url of memcache
|
||||
* @return CacheMemcache instance of CacheMemcache
|
||||
*/
|
||||
function getInstance($url){
|
||||
if(!$GLOBALS['__CacheMemcache__']) {
|
||||
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
||||
|
|
@ -17,6 +30,13 @@ class CacheMemcache extends CacheBase {
|
|||
return $GLOBALS['__CacheMemcache__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* Do not use this directly. You can use getInstance() instead.
|
||||
* @param string $url url of memcache
|
||||
* @return void
|
||||
*/
|
||||
function CacheMemcache($url){
|
||||
//$config['url'] = array('memcache://localhost:11211');
|
||||
$config['url'] = is_array($url)?$url:array($url);
|
||||
|
|
@ -28,6 +48,11 @@ class CacheMemcache extends CacheBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true;
|
||||
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) {
|
||||
|
|
@ -38,16 +63,47 @@ class CacheMemcache extends CacheBase {
|
|||
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique key of given key by path of XE
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @return string Return unique key
|
||||
*/
|
||||
function getKey($key){
|
||||
return md5(_XE_PATH_.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server
|
||||
*
|
||||
* CacheMemcache::put() stores an item $buff with $key on the memcached server.
|
||||
* Parameter $valid_time is expiration time in seconds. If it's 0, the item never expires
|
||||
* (but memcached server doesn't guarantee this item to be stored all the time, it could be delete from the cache to make place for other items).
|
||||
*
|
||||
* Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache,
|
||||
* because they can not be adequately represented in serialized state.
|
||||
*
|
||||
* @param string $key The key that will be associated with the item.
|
||||
* @param mixed $buff The variable to store. Strings and integers are stored as is, other types are stored serialized.
|
||||
* @param int $valid_time Expiration time of the item.
|
||||
* You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
|
||||
* If it's equal to zero, use the default valid time CacheMemcache::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
|
||||
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$_key = $this->getKey($key);
|
||||
|
||||
|
|
@ -63,6 +119,16 @@ class CacheMemcache extends CacheBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server
|
||||
*
|
||||
* CacheMemcache::get() returns previously stored data if an item with such $key exists on the server at this moment.
|
||||
*
|
||||
* @param string $key The key to fetch
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0) {
|
||||
$_key = $this->getKey($key);
|
||||
$obj = $this->Memcache->get($_key);
|
||||
|
|
@ -78,15 +144,39 @@ class CacheMemcache extends CacheBase {
|
|||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server
|
||||
*
|
||||
* CacheMemcache::delete() deletes an item with tey $key.
|
||||
*
|
||||
* @param string $key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
$_key = $this->getKey($key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server(private)
|
||||
*
|
||||
* @see CacheMemcache::delete()
|
||||
* @param string $_key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
$this->Memcache->delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items at the server
|
||||
*
|
||||
* CacheMemcache::truncate() immediately invalidates all existing items.
|
||||
* CacheMemcache::truncate() doesn't actually free any resources, it only marks all the items as expired,
|
||||
* so occupied memory will be overwitten by new items.
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
return $this->Memcache->flush();
|
||||
}
|
||||
|
|
|
|||
72
classes/cache/CacheWincache.class.php
vendored
72
classes/cache/CacheWincache.class.php
vendored
|
|
@ -1,14 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* @class CacheWincache
|
||||
* Cache class for Wincache
|
||||
*
|
||||
* Wincache Handler
|
||||
*
|
||||
* @author Arnia (support@xpressengine.org)
|
||||
* @brief Wincache Handler
|
||||
* @version 0.1
|
||||
**/
|
||||
|
||||
class CacheWincache extends CacheBase {
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
*/
|
||||
var $valid_time = 36000;
|
||||
|
||||
/**
|
||||
* Get instance of CacheWincache
|
||||
*
|
||||
* @param void $opt Not used
|
||||
* @return CacheWincache instance of CacheWincache
|
||||
*/
|
||||
function getInstance($opt=null){
|
||||
if(!$GLOBALS['__CacheWincache__']) {
|
||||
$GLOBALS['__CacheWincache__'] = new CacheWincache();
|
||||
|
|
@ -16,18 +26,47 @@ class CacheWincache extends CacheBase {
|
|||
return $GLOBALS['__CacheWincache__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheWincache(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
return function_exists('wincache_ucache_set');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a variable in user cache and overwrites a variable if it already exists in the cache
|
||||
*
|
||||
* @param string $key Store the variable using this $key value.
|
||||
* If a variable with same $key is already present the function will overwrite the previous value with the new one.
|
||||
* @param mixed $buff Value of a variable to store. $value supports all data types except resources, such as file handlers.
|
||||
* @param int $valid_time Time for the variable to live in the cache in seconds.
|
||||
* After the value specified in ttl has passed the stored variable will be deleted from the cache.
|
||||
* If no ttl is supplied, use the default valid time CacheWincache::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
return wincache_ucache_set(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
|
|
@ -42,6 +81,14 @@ class CacheWincache extends CacheBase {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a variable stored in the user cache
|
||||
*
|
||||
* @param string $key The $key that was used to store the variable in the cache.
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
|
|
@ -55,15 +102,32 @@ class CacheWincache extends CacheBase {
|
|||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache(private)
|
||||
*
|
||||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
wincache_ucache_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue