summaryrefslogtreecommitdiff
path: root/framework/caching/dependencies/CCacheDependency.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/caching/dependencies/CCacheDependency.php')
-rw-r--r--framework/caching/dependencies/CCacheDependency.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/framework/caching/dependencies/CCacheDependency.php b/framework/caching/dependencies/CCacheDependency.php
new file mode 100644
index 0000000..ca0f318
--- /dev/null
+++ b/framework/caching/dependencies/CCacheDependency.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * CCacheDependency class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+/**
+ * CCacheDependency is the base class for cache dependency classes.
+ *
+ * CCacheDependency implements the {@link ICacheDependency} interface.
+ * Child classes should override its {@link generateDependentData} for
+ * actual dependency checking.
+ *
+ * @property boolean $hasChanged Whether the dependency has changed.
+ * @property mixed $dependentData The data used to determine if dependency has been changed.
+ * This data is available after {@link evaluateDependency} is called.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CCacheDependency.php 3426 2011-10-25 00:01:09Z alexander.makarow $
+ * @package system.caching.dependencies
+ * @since 1.0
+ */
+class CCacheDependency extends CComponent implements ICacheDependency
+{
+ private $_data;
+
+ /**
+ * 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()
+ {
+ $this->_data=$this->generateDependentData();
+ }
+
+ /**
+ * @return boolean whether the dependency has changed.
+ */
+ public function getHasChanged()
+ {
+ return $this->generateDependentData()!=$this->_data;
+ }
+
+ /**
+ * @return mixed the data used to determine if dependency has been changed.
+ * This data is available after {@link evaluateDependency} is called.
+ */
+ public function getDependentData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * Generates the data needed to determine if dependency has been changed.
+ * Derived classes should override this method to generate actual dependent data.
+ * @return mixed the data needed to determine if dependency has been changed.
+ */
+ protected function generateDependentData()
+ {
+ return null;
+ }
+} \ No newline at end of file