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?
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, ];
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.
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) 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With