yii2: Failed to instantiate component or class "cache".

What steps will reproduce the problem?

Since version 2.0.33 the urlManager will throw an exception if cache component is not properly configured.

Failed to instantiate component or class "cache".

Now the out of the box setup process is disturbed i would say. Assuming the following config:

return [
'id' => 'luya-test-case',
'basePath' => dirname(__DIR__),
'components' => [
	'urlManager' => [
	    'rules' => [
		// my rules goes here
	    ]
	],
	'db' => [
	    'class' => 'yii\db\Connection',
	    'dsn' => 'sqlite::memory:',
	],
];

Before version 2.0.33 it was possible to run this code above, but since version 2.0.33 if have to either setup cache component (for example using DummyCache) or set urlManager::$cache to null.

Additional info

Q A
Yii version 2.0.33
PHP version all
Operating system all

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (23 by maintainers)

Commits related to this issue

Most upvoted comments

Logging a warning sounds like a compromise but it would spam logs a lot in @nadar case.

What’s your argument against UrlManager::$cache = null by default?

Because it will introduce performance regression, which is the worse regression possible, since it will be hard to notice. It is also not pragmatic - in most cases you have cache configured and you want to use it in UrlManager. Optimizing default configuration for an edge case does not seems to like Yii-way.

IMO the situation now can’t be solved without BC break anyway.

Converting exception to Yii::warning() should be BC and still give you a clue that your configuration is not optimal.

Yeah, right, nevermind then. Also not really fix for this issue. I did not read everything before responding.

Actually I’d vote to set UrlManager::$cache to null by default and add an upgrade note to 2.0.34.