diff options
author | xue <> | 2006-04-09 15:18:05 +0000 |
---|---|---|
committer | xue <> | 2006-04-09 15:18:05 +0000 |
commit | bfa60270a735a7a08a545a9bc1c972e8bf0bc590 (patch) | |
tree | 032f3bb44f1cbf96cf3c311082a3a32b146ca277 /framework/Web/UI | |
parent | d8122a0f98137822b0ea20f7602d105fcb2fe962 (diff) |
Fixed a bug about determining the cache key in TOutputCache.
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/TControl.php | 10 | ||||
-rw-r--r-- | framework/Web/UI/TTemplateManager.php | 20 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TCheckBoxList.php | 2 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TOutputCache.php | 38 |
4 files changed, 54 insertions, 16 deletions
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index f5f77513..cc6a6740 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -130,7 +130,7 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable /**
* @var string control unique ID
*/
- private $_uid='';
+ private $_uid=null;
/**
* @var TControl parent of the control
*/
@@ -366,8 +366,9 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable */
public function getUniqueID()
{
- if($this->_uid==='') // need to build the UniqueID
+ if($this->_uid==='' || $this->_uid===null) // need to build the UniqueID
{
+ $this->_uid=''; // set to not-null, so that clearCachedUniqueID() may take action
if($namingContainer=$this->getNamingContainer())
{
if($this->getPage()===$namingContainer)
@@ -1062,6 +1063,7 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable $control->generateAutomaticID();
else
$namingContainer->clearNameTable();
+ $control->clearCachedUniqueID($control instanceof INamingContainer);
}
if($this->_stage>=self::CS_CHILD_INITIALIZED)
@@ -1557,13 +1559,13 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable */
private function clearCachedUniqueID($recursive)
{
- $this->_uid='';
- if($recursive && isset($this->_rf[self::RF_CONTROLS]))
+ if($recursive && $this->_uid!==null && isset($this->_rf[self::RF_CONTROLS]))
{
foreach($this->_rf[self::RF_CONTROLS] as $control)
if($control instanceof TControl)
$control->clearCachedUniqueID($recursive);
}
+ $this->_uid=null;
}
/**
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 73a336c8..07d65fd0 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -11,6 +11,11 @@ */
/**
+ * Includes TOutputCache class file
+ */
+Prado::using('System.Web.UI.WebControls.TOutputCache');
+
+/**
* TTemplateManager class
*
* TTemplateManager manages the loading and parsing of control templates.
@@ -193,6 +198,10 @@ class TTemplate extends TApplicationComponent implements ITemplate * @var boolean whether this template is a source template
*/
private $_sourceTemplate=true;
+ /**
+ * @var string hash code of the template
+ */
+ private $_hashCode='';
/**
@@ -212,6 +221,7 @@ class TTemplate extends TApplicationComponent implements ITemplate $this->_tplFile=$tplFile;
$this->_startingLine=$startingLine;
$this->_content=$template;
+ $this->_hashCode=md5($template);
$this->parse($template);
$this->_content=null; // reset to save memory
}
@@ -242,6 +252,14 @@ class TTemplate extends TApplicationComponent implements ITemplate }
/**
+ * @return string hash code that can be used to identify the template
+ */
+ public function getHashCode()
+ {
+ return $this->_hashCode;
+ }
+
+ /**
* @return array the parsed template
*/
public function &getItems()
@@ -271,6 +289,8 @@ class TTemplate extends TApplicationComponent implements ITemplate if(isset($object[2])) // component
{
$component=Prado::createComponent($object[1]);
+ if($component instanceof TOutputCache)
+ $component->setCacheKeyPrefix($this->_hashCode.$key);
$properties=&$object[2];
if($component instanceof TControl)
{
diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index 8a106b46..2f0cce7c 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -309,7 +309,7 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont if($item->getEnabled())
{
$checked=isset($values[$key]);
- if($item->getSelected()!=$checked)
+ if($item->getSelected()!==$checked)
{
$item->setSelected($checked);
if(!$this->_changedEventRaised)
diff --git a/framework/Web/UI/WebControls/TOutputCache.php b/framework/Web/UI/WebControls/TOutputCache.php index 08f60f90..a19965b0 100644 --- a/framework/Web/UI/WebControls/TOutputCache.php +++ b/framework/Web/UI/WebControls/TOutputCache.php @@ -48,10 +48,17 @@ * or is invalidated, while that by the outer cache not, the outer cached
* content will be used.
*
+ * Note, TOutputCache is effective only for non-postback page requests
+ * and when cache module is enabled.
+ *
+ * Do not attempt to address child controls of TOutputCache when the cached
+ * content is to be used. Use {@link getContentCached ContentCached} property
+ * to determine whether the content is cached or not.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
- * @since 3.0
+ * @since 3.1
*/
class TOutputCache extends TControl implements INamingContainer
{
@@ -66,6 +73,7 @@ class TOutputCache extends TControl implements INamingContainer private $_state;
private $_actions=array();
private $_varyByParam='';
+ private $_keyPrefix='';
/**
* Returns a value indicating whether body contents are allowed for this control.
@@ -184,10 +192,8 @@ class TOutputCache extends TControl implements INamingContainer */
protected function loadStateRecursive(&$state,$needViewState=true)
{
- if($this->_dataCached)
- parent::loadStateRecursive($this->_state,$needViewState);
- else
- parent::loadStateRecursive($state,$needViewState);
+ $st=unserialize($state);
+ parent::loadStateRecursive($st,$needViewState);
}
/**
@@ -202,13 +208,13 @@ class TOutputCache extends TControl implements INamingContainer {
if($this->_dataCached)
return $this->_state;
- else if($this->_cacheAvailable)
+ else
{
- $this->_state=parent::saveStateRecursive($needViewState);
+ $st=parent::saveStateRecursive($needViewState);
+ // serialization is needed to avoid undefined classes when loading state
+ $this->_state=serialize($st);
return $this->_state;
}
- else
- return parent::saveStateRecursive($needViewState);
}
/**
@@ -251,10 +257,20 @@ class TOutputCache extends TControl implements INamingContainer $name=trim($name);
$params[$name]=$request->itemAt($name);
}
- return self::CACHE_ID_PREFIX.$this->getUniqueID().serialize($params);
+ return self::CACHE_ID_PREFIX.$this->_keyPrefix.$this->getUniqueID().serialize($params);
}
else
- return self::CACHE_ID_PREFIX.$this->getUniqueID();
+ return self::CACHE_ID_PREFIX.$this->_keyPrefix.$this->getUniqueID();
+ }
+
+ /**
+ * Sets the prefix of the cache key.
+ * This method is used internally by {@link TTemplate}.
+ * @param string key prefix
+ */
+ public function setCacheKeyPrefix($value)
+ {
+ $this->_keyPrefix=$value;
}
/**
|