TagDependency
API reference › yii › caching › TagDependency
TagDependency associates a cached data item with one or multiple $tags.
By calling invalidate(), you can invalidate all cached data items that are associated with the specified tag name(s).
// setting multiple cache keys to store data forever and tagging them with "user-123"Yii::$app->cache->set('user_42_profile', '', 0, new TagDependency(['tags' => 'user-123']));Yii::$app->cache->set('user_42_stats', '', 0, new TagDependency(['tags' => 'user-123']));
// invalidating all keys tagged with "user-123"TagDependency::invalidate(Yii::$app->cache, 'user-123');For more details and usage information on Cache, see the guide article on caching.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$data | mixed | The dependency data that is saved in cache and later is compared with the latest dependency data. Default: null. | Dependency |
$reusable | bool | Whether this dependency is reusable or not. Default: false. | Dependency |
$tags | string| | A list of tag names for this dependency. Default: []. | TagDependency |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
evaluateDependency() | Evaluates the dependency by generating and saving the data related with dependency. | Dependency |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
invalidate() static | Invalidates all of the cached data items that are associated with any of the specified $tags. | TagDependency |
isChanged() | Checks whether the dependency is changed. | TagDependency |
resetReusableData() static | Resets all cached data for reusable dependencies. | Dependency |
generateDependencyData() protected | Generates the data needed to determine if dependency has been changed. | TagDependency |
generateReusableHash() protected | Generates a unique hash that can be used for retrieving reusable dependency data. | Dependency |
getTimestamps() protected | Returns the timestamps for the specified tags. | TagDependency |
touchKeys() protected static | Generates the timestamp for the specified cache keys. | TagDependency |
Property details
Section titled “Property details”$tags
Section titled “$tags ”public string|array $tags = []A list of tag names for this dependency.
For a single tag, you may specify it as a string.
Method details
Section titled “Method details”invalidate()
Section titled “invalidate() ”public static function invalidate(yii\caching\CacheInterface $cache, string|array $tags): mixedInvalidates all of the cached data items that are associated with any of the specified $tags.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheInterface | The cache component that caches the data items |
$tags | string| |
Returns
mixed
isChanged()
Section titled “isChanged() ”public function isChanged(mixed $cache): boolChecks whether the dependency is changed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | mixed | The cache component that is currently evaluating this dependency |
Returns
bool: Whether the dependency has changed.
Since
2.0.11
generateDependencyData()
Section titled “generateDependencyData() ”protected function generateDependencyData(yii\caching\CacheInterface $cache): mixedGenerates the data needed to determine if dependency has been changed.
This method does nothing in this class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheInterface | The cache component that is currently evaluating this dependency |
Returns
mixed: The data needed to determine if dependency has been changed.
getTimestamps()
Section titled “getTimestamps() ”protected function getTimestamps(yii\caching\CacheInterface $cache, string[] $tags): arrayReturns the timestamps for the specified tags.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheInterface | |
$tags | string[] |
Returns
array: The timestamps indexed by the specified tags.
touchKeys()
Section titled “touchKeys() ”protected static function touchKeys(yii\caching\CacheInterface $cache, string[] $keys): arrayGenerates the timestamp for the specified cache keys.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheInterface | |
$keys | string[] |
Returns
array: The timestamp indexed by cache keys