demo icon indicating copy to clipboard operation
demo copied to clipboard

make keyPrefix default to $app->id for host-shared caches like Apc, Memcache

Open dicrtarasov opened this issue 6 years ago • 4 comments

For shared caches, like APCu, Memcache, the defaut behaviour require to use keyPrefix, because of interpolability of hosting application, which share caches. So, defult configuration is not usabled.

I'm proposing set keyPrefix to \Yii::$app->id by default, so, the default configuration of \yii\cache\ApcCache, \yii\cache\MemCache become usable.

Q A
Yii version 2.0.20
PHP version 7.2
Operating system debian linux

dicrtarasov avatar Jun 09 '19 09:06 dicrtarasov

That would cause backwards compatibility break. Won't be done in 2.x.

samdark avatar Jun 09 '19 10:06 samdark

@samdark lets implements it in 3.x

$app->id is the best place for Cache::keyPrefix, and the default configuration is not suitable to work because of cache intersect conflicts in multiple web-applications.

So small code for big enhancements. Settings Cache::keyPrefix defaults to Application::id rather then empty is the good reason.

Also, this will not "cause backwards compatibility break" in existing 2.x applications code, because the key prefix is not using in program logic never. Only empty keyPrefix may cause conflicts.

dicrtarasov avatar Aug 24 '19 15:08 dicrtarasov

Could be done in the default app config.

samdark avatar Aug 24 '19 19:08 samdark

yes! for ex. as Requres::cookieValidationKey is generated in default config when installing :) The difference is, the Cache::prefixKey is better in human-readable variant.

dicrtarasov avatar Aug 24 '19 21:08 dicrtarasov