yii\caching\TagDependency::invalidate PHP Метод

invalidate() публичный статический Метод

Invalidates all of the cached data items that are associated with any of the specified [[tags]].
public static invalidate ( Cache $cache, string | array $tags )
$cache Cache the cache component that caches the data items
$tags string | array
    public static function invalidate($cache, $tags)
    {
        $keys = [];
        foreach ((array) $tags as $tag) {
            $keys[] = $cache->buildKey([__CLASS__, $tag]);
        }
        static::touchKeys($cache, $keys);
    }

Usage Example

Пример #1
0
 /**
  * @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]);
 }
All Usage Examples Of yii\caching\TagDependency::invalidate