php yii-caching-TagDependency类(方法)实例源码

下面列出了php yii-caching-TagDependency 类(方法)源码代码实例,从而了解它的用法。

作者:tqsq200    项目:dotplant   
/**
  * @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]);
 }

作者:tqsq200    项目:dotplant   
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())]);
 }

作者:lzpfm    项目:dotplant   
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');
 }

作者:AtuinCM    项目:app   
/**
  * 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));
         }
     }
 }

作者:how    项目:yii   
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'));
 }

作者:DevGroup-r    项目:dotplant-monste   
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;
 }

作者:lzpfm    项目:dotplant   
/**
  * @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]));
 }

作者:andreyklue    项目:yii2-catalog-modul   
/**
  * Переносик категорию
  * @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];
 }

作者:luoch    项目:iisn   
/**
  * Ivalidate cache
  */
 protected function invalidate()
 {
     if (Configs::instance()->cache !== null) {
         TagDependency::invalidate(Configs::instance()->cache, self::CACHE_TAG);
     }
 }

作者:flarm    项目:dotplant   
/**
  * @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);
 }

作者:max-we    项目:yii2-app-advanced-autoEn   
/**
  * Ivalidate cache
  */
 public static function invalidate()
 {
     if (Configs::cache() !== null) {
         TagDependency::invalidate(Configs::cache(), self::CACHE_TAG);
     }
 }

作者:lav4    项目:yii2-translated-behavior-dem   
public function invalidateCache()
 {
     TagDependency::invalidate(Yii::$app->cache, self::$cacheKey);
 }

作者:scarnero    项目:yii2-tutoria   
/**
  * 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']);
 }

作者:webvimar    项目:ybc-conten   
/**
  * Invalidate cache
  */
 public function afterDelete()
 {
     TagDependency::invalidate(Yii::$app->cache, ContentModule::CACHE_TAG);
     parent::afterDelete();
 }

作者:radiata-cm    项目:radiat   
static function delete($tags = '')
 {
     TagDependency::invalidate(Yii::$app->cache, $tags);
 }

作者:Razzwa    项目:dotplant   
public function beforeSave($insert)
 {
     if (empty($this->breadcrumbs_label)) {
         $this->breadcrumbs_label = $this->name;
     }
     if (empty($this->h1)) {
         $this->h1 = $this->name;
     }
     if (empty($this->title)) {
         $this->title = $this->name;
     }
     $object = Object::getForClass(static::className());
     \yii\caching\TagDependency::invalidate(Yii::$app->cache, ['Images:' . $object->id . ':' . $this->id]);
     return parent::beforeSave($insert);
 }

作者:Sywooc    项目:AVSProduc   
/**
  *
  */
 protected function invalidateTags()
 {
     TagDependency::invalidate($this->getCache(), array_map(function ($tag) {
         if (is_callable($tag)) {
             $tag = call_user_func($tag, $this->owner);
         }
         return $tag;
     }, $this->tags));
 }

作者:kaliba    项目:magesk   
/**
  * Refresh cms widget
  * @param int $id Widget ID
  */
 public static function refreshWidget($id)
 {
     TagDependency::invalidate(Yii::$app->commonCache, self::getCacheTag($id));
 }

作者:reuhtt    项目:yii2-admi   
/**
  * Refresh file cache
  * @static
  */
 public static function refreshFileCache()
 {
     if (($cache = Yii::$app->getCache()) !== null) {
         TagDependency::invalidate($cache, static::getGroup(static::FILE_GROUP));
     }
 }

作者:kronos77    项目:dotplant   
/**
  *
  */
 public function invalidateModelCache()
 {
     TagDependency::invalidate(Yii::$app->cache, [ActiveRecordHelper::getObjectTag(PropertyGroup::className(), $this->property_group_id), ActiveRecordHelper::getObjectTag(Property::className(), $this->id)]);
 }


问题


面经


文章

微信
公众号

扫码关注公众号