yiisoft/yii2-app-basic

enableSchemaCache doesn't work

inwoker opened this issue · 4 comments

What steps will reproduce the problem?

1)Create a new basic app
2)Create some model and table. Insert some dummy data into table.
3)Write code to show the dummy data.
4)Set up in db config: enableSchemaCache to true and uncomment schemaCacheDuration and schemaCache.

What's expected?

There to be less sql queries when enableSchemaCache is enabled which is not the case.

What do you get instead?

Schema is never cached or cache is not read, which causes additional SQL queries on every request

Additional info

Q A
Yii vesion 2.0.41
PHP version 8.0.3
Operating system Ubuntu linux

Please provide your cache and db config.

I think I figured out the reason. Or at least how to fix it. I use homestead with folders type: "nfs". When I disable it - it works ok. So it seems there is some problem with cache when using nfs.

Just in case, thing you requested:

If you mean db config in db.php:
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=databasename',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8mb4',
'enableSchemaCache' => true,
'schemaCacheDuration' => 3600, // 1 hour
'schemaCache' => 'cache',

If you mean table:
CREATE TABLE blog (
id INT(10) NOT NULL AUTO_INCREMENT,
title VARCHAR(191) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
slug VARCHAR(191) NULL DEFAULT NULL COLLATE 'utf8mb4_bin',ss_test
image VARCHAR(191) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (id) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;

Cache:
https://drive.google.com/file/d/1SbPDLJUgaOfP94iZ91-iScW_nM3q399s/view?usp=sharing

Thanks. I meant cache is in "cache component config" but I guess it's FileCache, right? It looks like it's caused by some configuration issues on your provider side so we cannot help with that. Quick googling the problem gave me this for example, so it's not just you with that problem. Hope it can be fixed, cheers.

For future visitors: same setup for me, Homestead using nfs to sync files.

I've found that the file-based (data) cache does not work in this development environment. Writing to the cache is fine, but retrieving anything is always a miss. I'm guessing it's something to do with the timestamps on the cache files but didn't look into it. I use a database cache in local development - still performs well enough but lets me test the logic.