diff options
Diffstat (limited to 'framework')
| -rw-r--r-- | framework/Caching/TCache.php | 30 | ||||
| -rw-r--r-- | framework/Exceptions/messages.txt | 2 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TOutputCache.php | 38 | 
3 files changed, 63 insertions, 7 deletions
diff --git a/framework/Caching/TCache.php b/framework/Caching/TCache.php index e369f1df..b1d53525 100644 --- a/framework/Caching/TCache.php +++ b/framework/Caching/TCache.php @@ -44,18 +44,44 @@  abstract class TCache extends TModule implements ICache
  {
  	private $_prefix=null;
 +	private $_primary=true;
  	/**
  	 * Initializes the cache module.
  	 * This method initializes the cache key prefix and registers the cache module
 -	 * with the application.
 +	 * with the application if the cache is primary.
  	 * @param TXmlElement the module configuration
  	 */
  	public function init($config)
  	{
  		if($this->_prefix===null)
  			$this->_prefix=$this->getApplication()->getUniqueID();
 -		$this->getApplication()->setCache($this);
 +		if($this->_primary)
 +		{
 +			if($this->getApplication()->getCache()===null)
 +				$this->getApplication()->setCache($this);
 +			else
 +				throw new TConfigurationException('cache_primary_duplicated',get_class($this));
 +		}
 +	}
 +
 +	/**
 +	 * @return boolean whether this cache module is used as primary/system cache.
 +	 * A primary cache is used by PRADO core framework to cache data such as
 +	 * parsed templates, themes, etc.
 +	 */
 +	public function getPrimaryCache()
 +	{
 +		return $this->_primary;
 +	}
 +
 +	/**
 +	 * @param boolean whether this cache module is used as primary/system cache. Defaults to false.
 +	 * @see getPrimaryCache
 +	 */
 +	public function setPrimaryCache($value)
 +	{
 +		$this->_primary=TPropertyValue::ensureBoolean($value);
  	}
  	/**
 diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 028f7f75..257a4914 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -71,6 +71,7 @@ assetmanager_filepath_invalid			= TAssetManager is publishing an invalid file '{  assetmanager_tarchecksum_invalid		= TAssetManager is publishing a tar file with invalid checksum '{0}'.  assetmanager_tarfile_invalid			= TAssetManager is publishing an invalid tar file '{0}'. +cache_primary_duplicated				= At most one primary cache module is allowed. {0} is trying to register as another primary cache.  sqlitecache_extension_required			= TSqliteCache requires SQLite PHP extension.  sqlitecache_dbfile_required				= TSqliteCache.DbFile is required.  sqlitecache_connection_failed			= TSqliteCache database connection failed. {0}. @@ -293,6 +294,7 @@ parametermodule_parameterid_required	= Parameter element must have 'id' attribut  datagridcolumn_expression_invalid		= {0} is evaluating an invalid expression '{1}' : {2} +outputcache_cachemoduleid_invalid		= TOutputCache.CacheModuleID is set with an invalid cache module ID {0}. Either the module does not exist or does not implement ICache interface.  outputcache_duration_invalid			= {0}.Duration must be an integer no less than 0.  stack_data_not_iterable					= TStack can only fetch data from an array or a traversable object. diff --git a/framework/Web/UI/WebControls/TOutputCache.php b/framework/Web/UI/WebControls/TOutputCache.php index 76d74b47..b1a7fa93 100644 --- a/framework/Web/UI/WebControls/TOutputCache.php +++ b/framework/Web/UI/WebControls/TOutputCache.php @@ -63,6 +63,7 @@  class TOutputCache extends TControl implements INamingContainer
  {
  	const CACHE_ID_PREFIX='prado:outputcache';
 +	private $_cacheModuleID='';
  	private $_dataCached=false;
  	private $_cacheAvailable=false;
  	private $_cacheChecked=false;
 @@ -92,12 +93,23 @@ class TOutputCache extends TControl implements INamingContainer  		if(!$this->_cacheChecked)
  		{
  			$this->_cacheChecked=true;
 -			if(!$this->getPage()->getIsPostBack() && ($this->_cache=$this->getApplication()->getCache())!==null && $this->_duration>0)
 +			if(!$this->getPage()->getIsPostBack() && $this->_duration>0)
  			{
 -				$this->_cacheAvailable=true;
 -				$data=$this->_cache->get($this->getCacheKey());
 -				if(($this->_dataCached=($data!==false)))
 -					list($this->_contents,$this->_state,$this->_actions)=$data;
 +				if($this->_cacheModuleID!=='')
 +				{
 +					$this->_cache=$this->getApplication()->getModule($this->_cacheModuleID);
 +					if(!($this->_cache instanceof ICache))
 +						throw new TConfigurationException('outputcache_cachemoduleid_invalid',$this->_cacheModuleID);
 +				}
 +				else
 +					$this->_cache=$this->getApplication()->getCache();
 +				if($this->_cache!==null)
 +				{
 +					$this->_cacheAvailable=true;
 +					$data=$this->_cache->get($this->getCacheKey());
 +					if(($this->_dataCached=($data!==false)))
 +						list($this->_contents,$this->_state,$this->_actions)=$data;
 +				}
  			}
  		}
  	}
 @@ -272,6 +284,22 @@ class TOutputCache extends TControl implements INamingContainer  	}
  	/**
 +	 * @return string the ID of the cache module. Defaults to '', meaning the primary cache module is used.
 +	 */
 +	public function getCacheModuleID()
 +	{
 +		return $this->_cacheModuleID;
 +	}
 +
 +	/**
 +	 * @param string the ID of the cache module. If empty, the primary cache module will be used.
 +	 */
 +	public function setCacheModuleID($value)
 +	{
 +		$this->_cacheModuleID=$value;
 +	}
 +
 +	/**
  	 * Sets the prefix of the cache key.
  	 * This method is used internally by {@link TTemplate}.
  	 * @param string key prefix
  | 
