0

I just want to flush cache by variations, for example just flush the cache with variations id 5

I did't find any reference about flush params .. thanks in advance .

dev moore
  • 75
  • 8

2 Answers2

1

There is no way to flush cache by variation, at least not in any standardized way (implementation would differ for different cache storages, and for some of them this could be impossible). However you can invalidate caches using TagDependency - after calling TagDependency::invalidate() old cache still will be stored in cache storage, but it will be discarded on Cache::get() call.

rob006
  • 21,383
  • 5
  • 53
  • 74
  • Thank you do you have some example ? i have to test it – dev moore Dec 07 '21 at 11:24
  • and do you know any way to prevent cache for some dependcy ? for example I dont wnat to cache page cash for all pages in single action – dev moore Dec 11 '21 at 08:21
  • You may inject something like https://www.yiiframework.com/doc/api/2.0/yii-caching-dummycache as cache component for this action. – rob006 Dec 11 '21 at 11:12
  • There is a bug in the Yii2 since years. Removing cache entries by setting an tag invalid, with `TagDependency::invalidate()` is "currently" (since 2018) not working. https://stackoverflow.com/a/77000495/644817 – The Bndr Aug 29 '23 at 13:08
1

I could not implement through TagDependency::invalidate(). But I was able to find another solution. So, if you caching like this (in templates):

$this->beginCache('someKey', ['variations' => [$param1, $param2]]);

You can easy delete this cache from another place like this:

Yii::$app->cache->delete(['yii\widgets\FragmentCache', 'someKey', $param1, $param2]);
Roman
  • 11
  • 2