|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
-
-
- namespace yii\caching;
-
-
- abstract class Dependency extends \yii\base\Object
- {
-
-
- public $data;
-
-
- public $reusable = false;
-
-
-
- private static $_reusableData = [];
-
-
-
-
- public function evaluateDependency($cache)
- {
- if ($this->reusable) {
- $hash = $this->generateReusableHash();
- if (!array_key_exists($hash, self::$_reusableData)) {
- self::$_reusableData[$hash] = $this->generateDependencyData($cache);
- }
- $this->data = self::$_reusableData[$hash];
- } else {
- $this->data = $this->generateDependencyData($cache);
- }
- }
-
-
-
- public function getHasChanged($cache)
- {
- if ($this->reusable) {
- $hash = $this->generateReusableHash();
- if (!array_key_exists($hash, self::$_reusableData)) {
- self::$_reusableData[$hash] = $this->generateDependencyData($cache);
- }
- $data = self::$_reusableData[$hash];
- } else {
- $data = $this->generateDependencyData($cache);
- }
- return $data !== $this->data;
- }
-
-
-
- public static function resetReusableData()
- {
- self::$_reusableData = [];
- }
-
-
-
- protected function generateReusableHash()
- {
- $data = $this->data;
- $this->data = null;
- $key = sha1(serialize($this));
- $this->data = $data;
- return $key;
- }
-
-
-
- abstract protected function generateDependencyData($cache);
- }
|