summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe.Boulain <>2010-01-15 14:47:40 +0000
committerChristophe.Boulain <>2010-01-15 14:47:40 +0000
commit3da874c2f6667ca00808e5215d622b627b96ef62 (patch)
treef4fbd5d9d0f86bef5999ebabc8ae3b88253e0f9c
parentb067d9a3a809fab01ea9ad8127b667f17a551353 (diff)
Fixed #169
-rw-r--r--HISTORY1
-rw-r--r--UPGRADE4
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php2
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php2
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapCache.php80
5 files changed, 81 insertions, 8 deletions
diff --git a/HISTORY b/HISTORY
index d4bb1e9e..a743ad90 100644
--- a/HISTORY
+++ b/HISTORY
@@ -6,6 +6,7 @@ BUG: Issue#151 - TTextBox fails to display inital line break (Yves)
BUG: Issue#153 - Bug with calls like MyActiveRedorc->withText()->withUser()->find(...) and null result (Christophe)
BUG: Issue#157 - Enabled does not work properly on TActiveRadioButton/CheckBoxList controls (Bradley, Carl)
BUG: Issue#166 - E_NOTICE level error in TDataGatewayCommand (Carl)
+BUG: Issue#169 - FlushOnExecute on Basic CacheModel flushes all Application Cache (E.Letard, Christophe)
BUG: Issue#171 - <connection> tag in SqlMap config ignored in 3.1.5 and above, introduced by solving Issue#68 (Yves)
EHN: Issue#184 - THttpResponse doesn't support custom Content-Type headers, remove charset part of header if THttpResponse.Charset=false (Yves)
BUG: Issue#188 - TDbCache doesn't check if db connection is active. (Yves)
diff --git a/UPGRADE b/UPGRADE
index f22db112..cc550f7c 100644
--- a/UPGRADE
+++ b/UPGRADE
@@ -11,6 +11,10 @@ for both A and B.
Upgrading from v3.1.6
---------------------
+- The different SQLMap cache engines (TSQLMapFifoCache, TSQLMapLRUCache, TSQLMapApplicationCache) doesn't
+take anymore the cache size in their constructor. Instead, they take the cachemodel object who instanciated them.
+It shouldn't affect existing code, except if you instanciate one of this cache directly (i.e, without a <cachemodel>
+directive in your SQLMap configuration)
Upgrading from v3.1.5
---------------------
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index d85148eb..540a3acd 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -97,7 +97,7 @@ class TSqlMapCacheModel extends TComponent
public function initialize($cache=null)
{
if($cache===null)
- $this->_cache= Prado::createComponent($this->getImplementationClass());
+ $this->_cache= Prado::createComponent($this->getImplementationClass(), $this);
else
$this->_cache=$cache;
}
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
index f6e0acd5..c49a4219 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
@@ -710,7 +710,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
if(in_array(strtolower($name), $properties))
$cacheModel->{'set'.$name}((string)$value);
}
- $cache = Prado::createComponent($cacheModel->getImplementationClass());
+ $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel);
$this->setObjectPropFromNode($cache,$node,$properties);
foreach($node->xpath('property') as $propertyNode)
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
index 05b72e08..5262bdf8 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]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.Data.SqlMap
@@ -25,16 +25,17 @@ abstract class TSqlMapCache implements ICache
protected $_keyList;
protected $_cache;
protected $_cacheSize = 100;
+ protected $_cacheModel = null;
/**
* Create a new cache with limited cache size.
- * @param integer maxium number of items to cache.
+ * @param TSqlMapCacheModel $cacheModel.
*/
- public function __construct($cacheSize=100)
+ public function __construct($cacheModel=null)
{
$this->_cache = new TMap;
- $this->_cacheSize = intval($cacheSize);
$this->_keyList = new TList;
+ $this->_cacheModel=$cacheModel;
}
/**
@@ -173,20 +174,71 @@ class TSqlMapLruCache extends TSqlMapCache
*/
class TSqlMapApplicationCache implements ICache
{
+ protected $_cacheModel=null;
+
+ /**
+ * Create a new cache with limited cache size.
+ * @param TSqlMapCacheModel $cacheModel.
+ */
+ public function __construct($cacheModel=null)
+ {
+ $this->_cacheModel=$cacheModel;
+ }
+
+ /**
+ *
+ * @return string a KeyListID for the cache model.
+ */
+ protected function getKeyListId()
+ {
+ $id='keyList';
+ if ($this->_cacheModel instanceof TSqlMapCacheModel)
+ $id.='_'.$this->_cacheModel->getId();
+ return $id;
+ }
+ /**
+ * Retreive keylist from cache or create it if it doesn't exists
+ * @return TList
+ */
+ protected function getKeyList()
+ {
+ if (($keyList=$this->getCache()->get($this->getKeyListId()))===false)
+ {
+ $keyList=new TList();
+ $this->getCache()->set($this->getKeyListId(), $keyList);
+ }
+ return $keyList;
+ }
+
+ protected function setKeyList($keyList)
+ {
+ $this->getCache()->set($this->getKeyListId(), $keyList);
+ }
+
/**
* @param string item to be deleted.
*/
public function delete($key)
{
+ $keyList=$this->getKeyList();
+ $keyList->remove($key);
$this->getCache()->delete($key);
+ $this->setKeyList($keyList);
}
/**
- * Deletes all items in the cache.
+ * Deletes all items in the cache, only for data cached by sqlmap cachemodel
*/
public function flush()
{
- $this->getCache()->flush();
+ $keyList=$this->getKeyList();
+ $cache=$this->getCache();
+ foreach ($keyList as $key)
+ {
+ $cache->delete($key);
+ }
+ // Remove the old keylist
+ $cache->delete($this->getKeyListId());
}
/**
@@ -195,6 +247,16 @@ class TSqlMapApplicationCache implements ICache
public function get($key)
{
$result = $this->getCache()->get($key);
+ if ($result === false)
+ {
+ // if the key has not been found in cache (e.g expired), remove from keylist
+ $keyList=$this->getKeyList();
+ if ($keyList->contains($key))
+ {
+ $keyList->remove($key);
+ $this->setKeyList($keyList);
+ }
+ }
return $result === false ? null : $result;
}
@@ -206,6 +268,12 @@ class TSqlMapApplicationCache implements ICache
public function set($key, $value,$expire=0,$dependency=null)
{
$this->getCache()->set($key, $value, $expire,$dependency);
+ $keyList=$this->getKeyList();
+ if (!$keyList->contains($key))
+ {
+ $keyList->add($key);
+ $this->setKeyList($keyList);
+ }
}
/**