-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf51a76
commit a437f6f
Showing
6 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
use CComponent; | ||
|
||
/** | ||
* CacheItem represents cache item used for interaction with {@see \yii1tech\psr\cache\CacheItemPool}. | ||
* | ||
* @see \yii1tech\psr\cache\CacheItemPool | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
|
@@ -14,21 +18,22 @@ class CacheItem extends CComponent implements CacheItemContract | |
* @var string cache item key (ID). | ||
*/ | ||
private $_key; | ||
|
||
/** | ||
* @var mixed cache item value. | ||
*/ | ||
private $_value; | ||
|
||
/** | ||
* @var int|null cache item expire. | ||
*/ | ||
private $_expire; | ||
|
||
/** | ||
* @var \ICacheDependency|null dependency of the cache item. | ||
*/ | ||
private $_dependency; | ||
/** | ||
* @var string[] list of cache item tags. | ||
*/ | ||
private $_tags = []; | ||
|
||
/** | ||
* Sets the key for the current cache item. | ||
|
@@ -70,6 +75,14 @@ public function setDependency(?\ICacheDependency $dependency): self | |
return $this; | ||
} | ||
|
||
/** | ||
* @return string[] list of associated tags. | ||
*/ | ||
public function getTags(): array | ||
{ | ||
return $this->_tags; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -146,4 +159,18 @@ public function depends(?\ICacheDependency $dependency): self | |
{ | ||
return $this->setDependency($dependency); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function tag($tags): self | ||
{ | ||
if (!is_array($tags)) { | ||
$tags = [$tags]; | ||
} | ||
|
||
$this->_tags = $tags; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,13 @@ | |
* ]; | ||
* ``` | ||
* | ||
* > Note: for the cache item tags feature this class rely on wrapped Yii cache component, saving item tags | ||
* will silently fail if such support is not provided. You'll need to install and use "yii1tech/tagged-cache" | ||
* extension in order to make tags feature function. | ||
* | ||
* @see https://github.com/yii1tech/tagged-cache | ||
* @see \yii1tech\psr\cache\CacheItem | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
|
@@ -198,7 +205,8 @@ public function save(CacheItemInterface $item): bool | |
$item->getKey(), | ||
$item->get(), | ||
$item->getExpire(), | ||
$item->getDependency() | ||
$item->getDependency(), | ||
$item->getTags() | ||
); | ||
} | ||
|
||
|
@@ -249,4 +257,12 @@ public function get(string $key, callable $callback) | |
|
||
return $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function invalidateTags(array $tags): bool | ||
{ | ||
return $this->getCache()->invalidateTags($tags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters