intersvyaz / yii-tags-dependency
Verification of the cache relevance based on Dependency mechanism of Yii framework and tags, which are also stored in cache
Installs: 56 387
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 10
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.0
- yiisoft/yii: 1.1.*
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-11-08 07:42:19 UTC
README
Verification of the cache relevance based on Dependency mechanism of Yii framework and tags, which are also stored in cache
Based on idea of Косыгин Александр < http://habrahabr.ru/users/kosalnik/ > described at http://habrahabr.ru/post/159079/
Installation via Composer
php composer.phar require intersvyaz/yii-tags-dependency:*
Configuration
- This extension require configured cache
Base Usage
<?php use Intersvyaz\Cache\TagsDependency; $cache = \Yii::app()->cache; // save any value into cache with this dependency $cache->set('cacheKey', 'cacheValue', 0, new TagsDependency(['A', 'B'])); // check if there is a value in cache var_dump($cache->get('cacheKey')); // remove (invalidate) one or several tags TagsDependency::clearTags(['A']); // check if cached value is absent in cache var_dump($cache->get('cacheKey'));
CacheTagBehavior usage
class TestActiveRecord extends \CActiveRecord { // ... public function behaviors() { return [ 'cacheTagBehavior' => [ 'class' => CacheTagBehavior::class, ] ]; } // ... } // in other code: $models = TestActiveRecord::model()->cacheTag(3600, $dependency)->findAll(); // ... // read query from cache $models = TestActiveRecord::model()->cacheTag(3600, $dependency)->findAll(); // ... $model2 = TestActiveRecord::model()->findByPk(2); $model2->title = 'test'; $model2->save(); // ... // cache invalid, read query from db $models = TestActiveRecord::model()->cacheTag(3600, $dependency)->findAll();