1 | <?php |
||
21 | abstract class Dependency extends \yii\base\Object |
||
22 | { |
||
23 | /** |
||
24 | * @var mixed the dependency data that is saved in cache and later is compared with the |
||
25 | * latest dependency data. |
||
26 | */ |
||
27 | public $data; |
||
28 | /** |
||
29 | * @var bool whether this dependency is reusable or not. True value means that dependent |
||
30 | * data for this cache dependency will be generated only once per request. This allows you |
||
31 | * to use the same cache dependency for multiple separate cache calls while generating the same |
||
32 | * page without an overhead of re-evaluating dependency data each time. Defaults to false. |
||
33 | */ |
||
34 | public $reusable = false; |
||
35 | |||
36 | /** |
||
37 | * @var array static storage of cached data for reusable dependencies. |
||
38 | */ |
||
39 | private static $_reusableData = []; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Evaluates the dependency by generating and saving the data related with dependency. |
||
44 | * This method is invoked by cache before writing data into it. |
||
45 | * @param Cache $cache the cache component that is currently evaluating this dependency |
||
46 | */ |
||
47 | 8 | public function evaluateDependency($cache) |
|
59 | |||
60 | /** |
||
61 | * @deprecated since version 2.0.11. Will be removed in version 2.1 |
||
62 | */ |
||
63 | public function getHasChanged($cache) |
||
67 | |||
68 | /** |
||
69 | * Checks whether the dependency is changed |
||
70 | * @param Cache $cache the cache component that is currently evaluating this dependency |
||
71 | * @return bool whether the dependency has changed. |
||
72 | */ |
||
73 | 1 | public function isChanged($cache) |
|
86 | |||
87 | /** |
||
88 | * Resets all cached data for reusable dependencies. |
||
89 | */ |
||
90 | 1 | public static function resetReusableData() |
|
94 | |||
95 | /** |
||
96 | * Generates a unique hash that can be used for retrieving reusable dependency data. |
||
97 | * @return string a unique hash value for this cache dependency. |
||
98 | * @see reusable |
||
99 | */ |
||
100 | 1 | protected function generateReusableHash() |
|
108 | |||
109 | /** |
||
110 | * Generates the data needed to determine if dependency is changed. |
||
111 | * Derived classes should override this method to generate the actual dependency data. |
||
112 | * @param Cache $cache the cache component that is currently evaluating this dependency |
||
113 | * @return mixed the data needed to determine if dependency has been changed. |
||
114 | */ |
||
115 | abstract protected function generateDependencyData($cache); |
||
116 | } |
||
117 |