本文整理汇总了PHP中yii\caching\TagDependency::invalidate方法的典型用法代码示例。如果您正苦于以下问题:PHP TagDependency::invalidate方法的具体用法?PHP TagDependency::invalidate怎么用?PHP TagDependency::invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\caching\TagDependency
的用法示例。
在下文中一共展示了TagDependency::invalidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->model === null) {
throw new InvalidConfigException("Model should be set for WarehousesRemains widget");
}
$state = $this->model->getWarehousesState();
$activeWarehousesIds = Warehouse::activeWarehousesIds();
$remains = [];
foreach ($state as $remain) {
$remains[$remain->warehouse_id] = $remain;
if (($key = array_search($remain->warehouse_id, $activeWarehousesIds)) !== false) {
unset($activeWarehousesIds[$key]);
}
}
// if we have new warehouses that not represented in warehouses state
if (count($activeWarehousesIds) > 0) {
foreach ($activeWarehousesIds as $id) {
// create new record with default values
$remain = new WarehouseProduct();
$remain->warehouse_id = $id;
$remain->product_id = $this->model->id;
$remain->save();
// add to remains
$remains[$remain->warehouse_id] = $remain;
}
TagDependency::invalidate(Yii::$app->cache, ActiveRecordHelper::getObjectTag($this->model->className(), $this->model->id));
}
return $this->render('warehouses-remains', ['model' => $this->model, 'remains' => $remains]);
}
示例2: down
public function down()
{
$tbl = '{{%backend_menu}}';
$this->update($tbl, ['route' => '/shop/backend-order/index'], ['route' => 'shop/backend-order/index']);
$this->update($tbl, ['route' => '/shop/backend-customer/index'], ['route' => 'shop/backend-customer/index']);
$this->update($tbl, ['route' => '/shop/backend-contragent/index'], ['route' => 'shop/backend-contragent/index']);
\yii\caching\TagDependency::invalidate(Yii::$app->cache, [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\backend\models\BackendMenu::className())]);
}
示例3: down
public function down()
{
$this->dropTable('{{%addon}}');
$this->dropTable('{{%addon_category}}');
$this->dropTable('{{%addon_bindings}}');
$this->delete('{{%object}}', ['name' => 'Addon']);
$this->delete('{{%backend_menu}}', ['name' => 'Addons']);
\yii\caching\TagDependency::invalidate(Yii::$app->cache, [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\backend\models\BackendMenu::className())]);
$this->dropColumn('{{%order_item}}', 'addon_id');
}
示例4: _deleteCache
/**
* Deletes the cache for the frontend and backend loaded data using makeCacheTag method
*
* @param Event $event
*/
public function _deleteCache(Event $event)
{
$frontend = [0, 1];
$backend = [0, 1];
foreach ($frontend as $_f) {
foreach ($backend as $_b) {
TagDependency::invalidate(Yii::$app->cache, self::makeCacheTag($_f, $_b));
}
}
}
示例5: testInvalidate
public function testInvalidate()
{
$cache = new FileCache(['cachePath' => '@yiiunit/runtime/cache']);
// single tag test
$cache->set('a1', 11, 0, new TagDependency(['tags' => 't1']));
$cache->set('a2', 12, 0, new TagDependency(['tags' => 't1']));
$cache->set('b1', 21, 0, new TagDependency(['tags' => 't2']));
$cache->set('b2', 22, 0, new TagDependency(['tags' => 't2']));
$this->assertEquals(11, $cache->get('a1'));
$this->assertEquals(12, $cache->get('a2'));
$this->assertEquals(21, $cache->get('b1'));
$this->assertEquals(22, $cache->get('b2'));
TagDependency::invalidate($cache, 't1');
$this->assertFalse($cache->get('a1'));
$this->assertFalse($cache->get('a2'));
$this->assertEquals(21, $cache->get('b1'));
$this->assertEquals(22, $cache->get('b2'));
TagDependency::invalidate($cache, 't2');
$this->assertFalse($cache->get('a1'));
$this->assertFalse($cache->get('a2'));
$this->assertFalse($cache->get('b1'));
$this->assertFalse($cache->get('b2'));
// multiple tag test
$cache->set('a1', 11, 0, new TagDependency(['tags' => ['t1', 't2']]));
$cache->set('a2', 12, 0, new TagDependency(['tags' => 't1']));
$cache->set('b1', 21, 0, new TagDependency(['tags' => ['t1', 't2']]));
$cache->set('b2', 22, 0, new TagDependency(['tags' => 't2']));
$this->assertEquals(11, $cache->get('a1'));
$this->assertEquals(12, $cache->get('a2'));
$this->assertEquals(21, $cache->get('b1'));
$this->assertEquals(22, $cache->get('b2'));
TagDependency::invalidate($cache, 't1');
$this->assertFalse($cache->get('a1'));
$this->assertFalse($cache->get('a2'));
$this->assertFalse($cache->get('b1'));
$this->assertEquals(22, $cache->get('b2'));
TagDependency::invalidate($cache, 't2');
$this->assertFalse($cache->get('a1'));
$this->assertFalse($cache->get('a2'));
$this->assertFalse($cache->get('b1'));
$this->assertFalse($cache->get('b2'));
$cache->set('a1', 11, 0, new TagDependency(['tags' => ['t1', 't2']]));
$cache->set('a2', 12, 0, new TagDependency(['tags' => 't1']));
$cache->set('b1', 21, 0, new TagDependency(['tags' => ['t1', 't2']]));
$cache->set('b2', 22, 0, new TagDependency(['tags' => 't2']));
$this->assertEquals(11, $cache->get('a1'));
$this->assertEquals(12, $cache->get('a2'));
$this->assertEquals(21, $cache->get('b1'));
$this->assertEquals(22, $cache->get('b2'));
TagDependency::invalidate($cache, ['t1', 't2']);
$this->assertFalse($cache->get('a1'));
$this->assertFalse($cache->get('a2'));
$this->assertFalse($cache->get('b1'));
$this->assertFalse($cache->get('b2'));
}
示例6: setCustomization
public function setCustomization($block, $customization = [])
{
$this->validateBemSelector($block);
static::$identityMap[$block] = $customization;
$filename = $this->storagePath . $block . 'json';
$result = file_put_contents($filename, Json::encode($customization)) !== false;
if ($result === true) {
TagDependency::invalidate(Yii::$app->cache, ["GlobalCustomization:{$block}"]);
}
return $result;
}
示例7: run
/**
* @inheritdoc
*/
public function run()
{
$n = 0;
switch ($this->action) {
case CategoryMovementsButtons::ADD_ACTION:
$n = $this->add();
break;
case CategoryMovementsButtons::MOVE_ACTION:
$n = $this->move();
break;
}
$tags = [];
foreach ($this->items as $id) {
$tags[] = ActiveRecordHelper::getObjectTag(Product::className(), $id);
}
TagDependency::invalidate(Yii::$app->cache, $tags);
Yii::$app->session->setFlash('info', Yii::t('app', 'Items updated: {n}', ['n' => $n]));
}
示例8: moveCategory
/**
* Переносик категорию
* @param $parent integer
* @param $position integer
* @return array
*/
public function moveCategory($parent, $position)
{
// Очищаем ВСЕ кеши категорий
TagDependency::invalidate(Yii::$app->cache, ['category']);
$result = false;
$counts = [];
$parentCat = Category::findOne($parent);
// Новый родитель
$oldParentCat = Category::findOne($this->parent);
// Старый родитель
$this->parent = $parent;
// Если position = 0
if ($position === 0) {
// Добавляем в начало
$result = $this->prependTo($parentCat);
} else {
// Иначе, ищем категорию, после которой нужно добавить
$prevCategory = end($parentCat->children(1)->andWhere(['not in', 'id', $this->id])->limit($position)->all());
// Если нужный элемент найден
if ($prevCategory !== null) {
// Добавляем новый после нее
$result = $this->insertAfter($prevCategory);
}
}
// Пересчитываем cnt_products для всех НОВЫХ и СТАРЫХ родительских категорий
// Если товаров в категории нет, то и пересчитывать ничего не нужно
if (0 < $this->cnt_products) {
$parents = array_unique(array_merge([$oldParentCat->id], Category::getParentsIds($oldParentCat->id), [(int) $this->parent], Category::getParentsIds($this->parent)));
foreach ($parents as $p) {
$parentCategory = Category::findOne($p);
$parentCategory->cnt_products = Product::findAllInCatsAndSubCategories($parentCategory)->count();
$parentCategory->save();
$counts[$parentCategory->id] = $parentCategory->cnt_products;
}
}
return ['result' => $result, 'counts' => $counts];
}
示例9: invalidate
/**
* Ivalidate cache
*/
protected function invalidate()
{
if (Configs::instance()->cache !== null) {
TagDependency::invalidate(Configs::instance()->cache, self::CACHE_TAG);
}
}
示例10: beforeSave
/**
* @inheritdoc
*/
public function beforeSave($insert)
{
if (!$insert) {
// reset a cache tag to get a new parent model below
TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag(self::className())]);
}
$this->slug_compiled = $this->compileSlug();
TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag($this->className()), 'Page:' . $this->slug_compiled]);
TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag($this->className()), 'Page:' . $this->id . ':0']);
TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getCommonTag($this->className()), 'Page:' . $this->id . ':1']);
if (empty($this->breadcrumbs_label)) {
$this->breadcrumbs_label = $this->title;
}
if (empty($this->h1)) {
$this->h1 = $this->title;
}
return parent::beforeSave($insert);
}
示例11: invalidate
/**
* Ivalidate cache
*/
public static function invalidate()
{
if (Configs::cache() !== null) {
TagDependency::invalidate(Configs::cache(), self::CACHE_TAG);
}
}
示例12: invalidateCache
public function invalidateCache()
{
TagDependency::invalidate(Yii::$app->cache, self::$cacheKey);
}
示例13: actionDelete
/**
* Deletes an existing Book model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
\yii\caching\TagDependency::invalidate(Yii::$app->cache, 'books');
return $this->redirect(['index']);
}
示例14: afterDelete
/**
* Invalidate cache
*/
public function afterDelete()
{
TagDependency::invalidate(Yii::$app->cache, ContentModule::CACHE_TAG);
parent::afterDelete();
}
示例15: delete
static function delete($tags = '')
{
TagDependency::invalidate(Yii::$app->cache, $tags);
}