diff options
author | carl <> | 2008-10-13 10:46:23 +0000 |
---|---|---|
committer | carl <> | 2008-10-13 10:46:23 +0000 |
commit | 73daf45e030b66b045718d1878b28105f021d5ab (patch) | |
tree | 7f08c742d5f05630fd27f56669d234d9b227f1ba /framework/Caching | |
parent | ab018b4fd8244578adc12b1b48ecc4fe52e471d4 (diff) |
#848 - TCache "set" and "add" with empty values
Diffstat (limited to 'framework/Caching')
-rw-r--r-- | framework/Caching/TCache.php | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/framework/Caching/TCache.php b/framework/Caching/TCache.php index 27618e84..02a4ae3b 100644 --- a/framework/Caching/TCache.php +++ b/framework/Caching/TCache.php @@ -4,7 +4,7 @@ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Caching
@@ -136,7 +136,8 @@ abstract class TCache extends TModule implements ICache, ArrayAccess /**
* Stores a value identified by a key into cache.
* If the cache already contains such a key, the existing value and
- * expiration time will be replaced with the new ones.
+ * expiration time will be replaced with the new ones. If the value is
+ * empty, the cache key will be deleted.
*
* @param string the key identifying the value to be cached
* @param mixed the value to be cached
@@ -146,13 +147,18 @@ abstract class TCache extends TModule implements ICache, ArrayAccess */
public function set($id,$value,$expire=0,$dependency=null)
{
- $data=array($value,$dependency);
- return $this->setValue($this->generateUniqueKey($id),serialize($data),$expire);
+ if(empty($value) && $expire === 0)
+ $this->delete($id);
+ else
+ {
+ $data=array($value,$dependency);
+ return $this->setValue($this->generateUniqueKey($id),serialize($data),$expire);
+ }
}
/**
* Stores a value identified by a key into cache if the cache does not contain this key.
- * Nothing will be done if the cache already contains the key.
+ * Nothing will be done if the cache already contains the key or if value is empty.
* @param string the key identifying the value to be cached
* @param mixed the value to be cached
* @param integer the number of seconds in which the cached value will expire. 0 means never expire.
@@ -161,6 +167,8 @@ abstract class TCache extends TModule implements ICache, ArrayAccess */
public function add($id,$value,$expire=0,$dependency=null)
{
+ if(empty($value) && $expire === 0)
+ return false;
$data=array($value,$dependency);
return $this->addValue($this->generateUniqueKey($id),serialize($data),$expire);
}
@@ -710,4 +718,4 @@ class TCacheDependencyList extends TList }
}
-?> +?>
|