yiisoft / yii

Yii PHP Framework 1.1.x
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
4.84k stars 2.28k forks source link

schemaCachingDuration is not working #4561

Closed albertborsos closed 3 months ago

albertborsos commented 3 months ago

I realized the CDbConnection.schemaCachingDuration property has no effect. We use this config only in staging and production, but after the deploy we get exceptions for missing attributes.

That is why I wrote this test to prove that schemaCachingDuration settings does not work.

You can run this test from the tests folder:

php ../vendor/bin/phpunit framework/db/CDbConnectionTest.php --filter testSchemaCachingDuration

Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Tests pass?
Fixed issues
albertborsos commented 3 months ago

I was not fully accurate in the description. schemaCachingDuration has effect, because it caches the schema, but after the duration it does not invalidate the cached schema.

marcovtwout commented 3 months ago

If I read the code correctly, the duration is used between requests. But within one request table data is always cached (in https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php#L34 which is always checked first in https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php#L74). Can you confirm this is the case for you?

If you need to force new schema data within one request, you can call schema->refresh() as you've probably already seen.

albertborsos commented 3 months ago

thanks @marcovtwout , we have issues between requests. So you are right, my test cases are not correct. I will update it soon.

Since then I realized we use a custom cache which stores data in couchbase (correctly with expiration), but I have to investigate it more deeply.

For now, I close this ticket, since there is a lack of chance there is this bug in the framework for 10+ years.

Thanks.