Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable assets caching in Yii2?

Tags:

yii2

I'm writing my first Yii2 application and I want to disable the assets caching, while I'm developing.

Can I disable the caching using the ./config/ .php files?

like image 669
Kupigon Avatar asked Jan 20 '15 07:01

Kupigon


People also ask

How to disable cache in Yii2?

2) If you want disable caching in specific AssetBundle, use $publishOptions property: public $sourcePath = '...' // In order to use $publishOptions you should specify correct source path. public $publishOptions = [ 'forceCopy' => true, ];

How to clear db cache in Yii2?

When you need to invalidate all the stored cache data, you can call yii\caching\Cache::flush(). You can flush the cache from the console by calling yii cache/flush as well.

How to use caching in Yii2?

Simple Data Caching So we start by setting a value to be cached. To do so, we will also have to assign it a unique ID. For example: // Storing $value in Cache $value = "This is a variable that I am storing"; $id = "myValue"; $time = 30; // in seconds Yii::app()->cache->set($id, $value, $time);


1 Answers

1) Globally it's possible with help of AssetMananer. There is special option $forceCopy for this.

You can set it like this with component:

use Yii;

Yii::$app->assetManager->forceCopy = true;

Or in application config:

'components' => [
    'assetManager' => [
        'class' => 'yii\web\AssetManager',
        'forceCopy' => true,          
    ],
],

2) If you want disable caching in specific AssetBundle, use $publishOptions property:

public $sourcePath = '...' // In order to use $publishOptions you should specify correct source path.

public $publishOptions = [
    'forceCopy' => true,
];

Alternatively you can specify this like in option 1 with help of bundles property. For example:

'components' => [
    'assetManager' => [
        'class' => 'yii\web\AssetManager',
        'forceCopy' => true,          
        'bundles' => [
            'yii\bootstrap\BootstrapAsset' => [
                'forceCopy' => true,
            ],
        ],
    ],
],

But this:

'forceCopy' => YII_DEBUG,

is more flexible, because it disables this asset bundle caching only in debug mode, but allows on production server. YII_DEBUG is set in web/index.php.

like image 77
arogachev Avatar answered Oct 10 '22 11:10

arogachev