summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY1
-rw-r--r--framework/Caching/TCache.php20
2 files changed, 15 insertions, 6 deletions
diff --git a/HISTORY b/HISTORY
index dc4f888a..28883e2c 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,5 +1,6 @@
Version 3.1.3 To Be Released
============================
+ENH: Ticket#848 - TCache "set" and "add" with empty values (Carl)
ENH: Ticket#756 - TDateFormat & TNumberFormat - allow settings default text when Value isn't set. (Carl)
BUG: Ticket#834 - TDbCommandBuilder::applyOrdering(): Add support for function calls in ORDER BY clause (Knut)
BUG: Ticket#836 - TRatingList downgrade (Christophe)
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 &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 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
}
}
-?>
+?>