M
M
Maxim Timofeev2016-02-04 18:21:33
Yii
Maxim Timofeev, 2016-02-04 18:21:33

How to reset the frontend cache in Yii2?

yii has a wonderful method \Yii::$app->cache->flush(); which flushes the cache.
But if the admin is on a subdomain, then the cache is different and it cleans the admin cache. Can't think of a way to force it to clear in the frontend.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2016-06-03
@webinar

Are you talking about FileCache? Correctly?
Well, you just need to specify in common/config/main.php for the cache component

'cache' => [
            'class' => 'yii\caching\FileCache',
            'cachePath' => '@backend/runtime/cache'
        ],

Or somewhere else. In any folder in general. Otherwise, by default, the path '@frontend/runtime/cache' will be set for the component on the front, and '@backend/....' on the back, respectively, and when called from different subdomains, the component will go to different directories.

N
Nikita, 2016-02-04
@bitver

There may be better ways, but as an option, I can suggest initializing the front Application instance, as implemented in web/index.php, and calling $app->cache->flush(); In this case, if something changes in your front cache configurations, then everything will still work.
UPD: In order not to pull the entire application, you can create a cache component with a yii factory from the front config

J
jacksparrow, 2016-02-04
@jacksparrow

Then they will advise the correct option, but for now, make a controller on the front, whose duty will be to reset the cache and call it from the admin panel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question