1 | <?php |
||
29 | class TagDependency extends Dependency |
||
30 | { |
||
31 | /** |
||
32 | * @var string|array a list of tag names for this dependency. For a single tag, you may specify it as a string. |
||
33 | */ |
||
34 | public $tags = []; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Generates the data needed to determine if dependency has been changed. |
||
39 | * This method does nothing in this class. |
||
40 | * @param Cache $cache the cache component that is currently evaluating this dependency |
||
41 | 8 | * @return mixed the data needed to determine if dependency has been changed. |
|
42 | */ |
||
43 | 8 | protected function generateDependencyData($cache) |
|
44 | { |
||
45 | 8 | $timestamps = $this->getTimestamps($cache, (array) $this->tags); |
|
46 | 8 | ||
47 | 8 | $newKeys = []; |
|
48 | 5 | foreach ($timestamps as $key => $timestamp) { |
|
49 | 5 | if ($timestamp === false) { |
|
50 | 8 | $newKeys[] = $key; |
|
51 | 8 | } |
|
52 | 5 | } |
|
53 | 5 | if (!empty($newKeys)) { |
|
54 | $timestamps = array_merge($timestamps, static::touchKeys($cache, $newKeys)); |
||
55 | 8 | } |
|
56 | |||
57 | return $timestamps; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | 2 | public function isChanged($cache) |
|
64 | { |
||
65 | 2 | $timestamps = $this->getTimestamps($cache, (array) $this->tags); |
|
66 | 2 | return $timestamps !== $this->data; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Invalidates all of the cached data items that are associated with any of the specified [[tags]]. |
||
71 | * @param Cache $cache the cache component that caches the data items |
||
72 | * @param string|array $tags |
||
73 | */ |
||
74 | 2 | public static function invalidate($cache, $tags) |
|
82 | |||
83 | /** |
||
84 | * Generates the timestamp for the specified cache keys. |
||
85 | * @param Cache $cache |
||
86 | * @param string[] $keys |
||
87 | * @return array the timestamp indexed by cache keys |
||
88 | */ |
||
89 | 5 | protected static function touchKeys($cache, $keys) |
|
99 | |||
100 | /** |
||
101 | * Returns the timestamps for the specified tags. |
||
102 | * @param Cache $cache |
||
103 | * @param string[] $tags |
||
104 | * @return array the timestamps indexed by the specified tags. |
||
105 | */ |
||
106 | 8 | protected function getTimestamps($cache, $tags) |
|
119 | } |
||
120 |