yii1tech/tagged-cache
最新稳定版本:1.0.0
Composer 安装命令:
composer require yii1tech/tagged-cache
包简介
Provides support for tag aware cache for Yii1 application
README 文档
README
Yii1 Tag Aware Cache Extension
This extension provides tag aware cache for Yii1.
For license information check the LICENSE-file.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii1tech/tagged-cache
or add
"yii1tech/tagged-cache": "*"
to the "require" section of your composer.json.
Usage
This extension provides tag aware cache for Yii1. Tags allow you to organize cache items into groups, each of which can be cleared separately.
This extension introduces \yii1tech\cache\tagged\TagAwareCacheContract interface, which extends Yii standard \ICache, adding extra parameter
for the tags specification on saving data to the cache.
Application configuration example:
<?php return [ 'components' => [ 'cache' => [ 'class' => \yii1tech\cache\tagged\MemCache::class, // implements `\yii1tech\cache\tagged\TagAwareCacheContract` 'servers' => [ [ 'host' => 'memcache.server', 'port' => 11211, 'weight' => 100, ], ], ], // ... ], // ... ];
You may pass list of cache item tags as an extra argument to methods get() and add().
For example:
<?php $cacheKey = 'example-cache-key'; $value = Yii::app()->cache->get($cacheKey); if ($value === false) { $value = Yii::app()->db->createCommand('SELECT ...')->query(); // some heave SQL query. Yii::app()->cache->set( $cacheKey, // cache key $value, // value to be cached 3600, // cache expiration null, // dependency, empty in our case ['database', 'main'] // list of cache tags. ); }
You can clear all cache items associated with the specific tags using \yii1tech\cache\tagged\TagAwareCacheContract::invalidateTags() method.
For example:
<?php Yii::app()->cache->invalidateTags(['database']);
This extension provides several built-in cache drivers, which supports tags:
Please refer to the particular storage class for more details.
统计信息
- 总下载量: 1.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-08-08