You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					53 lines
				
				1.4 KiB
			
		
		
			
		
	
	
					53 lines
				
				1.4 KiB
			| 
											14 years ago
										 | <?php
 | ||
|  | /**
 | ||
|  |  * @link http://www.yiiframework.com/
 | ||
| 
											13 years ago
										 |  * @copyright Copyright (c) 2008 Yii Software LLC
 | ||
| 
											14 years ago
										 |  * @license http://www.yiiframework.com/license/
 | ||
|  |  */
 | ||
|  | 
 | ||
| 
											14 years ago
										 | namespace yii\caching;
 | ||
|  | 
 | ||
| 
											14 years ago
										 | /**
 | ||
| 
											14 years ago
										 |  * Dependency is the base class for cache dependency classes.
 | ||
| 
											14 years ago
										 |  *
 | ||
| 
											14 years ago
										 |  * Child classes should override its [[generateDependencyData()]] for generating
 | ||
|  |  * the actual dependency data.
 | ||
| 
											14 years ago
										 |  *
 | ||
|  |  * @property boolean $hasChanged Whether the dependency has changed.
 | ||
|  |  *
 | ||
|  |  * @author Qiang Xue <qiang.xue@gmail.com>
 | ||
| 
											14 years ago
										 |  * @since 2.0
 | ||
| 
											14 years ago
										 |  */
 | ||
| 
											14 years ago
										 | abstract class Dependency extends \yii\base\Object
 | ||
| 
											14 years ago
										 | {
 | ||
|  | 	/**
 | ||
| 
											14 years ago
										 | 	 * @var mixed the dependency data that is saved in cache and later is compared with the
 | ||
|  | 	 * latest dependency data.
 | ||
| 
											14 years ago
										 | 	 */
 | ||
| 
											14 years ago
										 | 	public $data;
 | ||
| 
											14 years ago
										 | 
 | ||
|  | 	/**
 | ||
|  | 	 * Evaluates the dependency by generating and saving the data related with dependency.
 | ||
|  | 	 * This method is invoked by cache before writing data into it.
 | ||
|  | 	 */
 | ||
|  | 	public function evaluateDependency()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$this->data = $this->generateDependencyData();
 | ||
| 
											14 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
|  | 	 * @return boolean whether the dependency has changed.
 | ||
|  | 	 */
 | ||
|  | 	public function getHasChanged()
 | ||
|  | 	{
 | ||
| 
											13 years ago
										 | 		return $this->generateDependencyData() !== $this->data;
 | ||
| 
											14 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
|  | 	 * Generates the data needed to determine if dependency has been changed.
 | ||
| 
											14 years ago
										 | 	 * Derived classes should override this method to generate the actual dependency data.
 | ||
| 
											14 years ago
										 | 	 * @return mixed the data needed to determine if dependency has been changed.
 | ||
|  | 	 */
 | ||
| 
											14 years ago
										 | 	abstract protected function generateDependencyData();
 | ||
| 
											13 years ago
										 | }
 |