schemacaching in yii2 yii\db\Connection

Enabling Schema Caching in Yii2

Hi everyone,

Ia m rather new to yii2 so my question might be a no-brainer for you guys.

I tried to enable schema caching in yii2 so I don’t get all the SHOW FULL COLUMNS FROM Queries when using ActiveRecords all the time.

In main.php I configured a CMemCache instance




		'cache' => array (

			'class' => 'yii\caching\CMemCache',

		),



And assigned the cache to the Connection class as follows




		'db' => [

			'class' => 'yii\db\Connection',

			'dsn' => 'mysql:host=localhost;dbname=curassist',

			'username' => 'some',

			'password' => 'some',

			'charset' => 'utf8',

			'schemaCache' => 'cache',

			'schemaCacheDuration' => '3600',

			'enableSchemaCache' => true,

		],



When I call a controller action now, I pretty much get a blank page (it stops rendering when accessing the database the first time I think) but no error or anything useful is displayed.

When I remove the

		'enableSchemaCache' => true,

Or set it to false, all works fine, but oviously it doesn’t perform any caching.

Any ideas what might be wrong?

Since the debugger doesn’t even get displayed there is nothing I can think of to figure out where the cause might be.

I also tried adding server and port settings for memcache, but no difference




		'cache' => array (

			'class' => 'yii\caching\CMemCache',

			'servers'=>array(

				array(

					'host'=>'localhost',

					'port'=>11211,

				),

			),

		),



Oh, and I verified that memcache is enabled.

Output from phpInfo:




memcache

memcache support	enabled

Version 	3.0.8

Revision 	$Revision: 329835 $


Directive	Local Value	Master Value

memcache.allow_failover	1	1

memcache.chunk_size	32768	32768

memcache.compress_threshold	20000	20000

memcache.default_port	11211	11211

memcache.hash_function	crc32	crc32

memcache.hash_strategy	consistent	consistent

memcache.lock_timeout	15	15

memcache.max_failover_attempts	20	20

memcache.protocol	ascii	ascii

memcache.redundancy	1	1

memcache.session_redundancy	2	2



Any ideas?

Thanks in advance

Paul

ok, I did some progress, in the server logs I found an error, indicating that the class CMemCache does not exists. I found one that is called "MemCache" in the vendor/yii… folder.

After setting that as the cach class to be used I got at least some more details out of yii.

Current config:




		'cache' => array (

			'class' => 'yii\caching\MemCache',

			'servers'=>array(

				array(

					'host'=>'localhost',

					'port'=>11211,

				),

			),

		),



Current Error:




exception 'yii\base\ErrorException' with message 'MemcachePool::get(): Server localhost (tcp 11211, udp 0) failed with: Connection refused (111)' in /var/www/virtualhosts/www.einzelpflegefachkraft.de/curassist-app/vendor/yiisoft/yii2/caching/MemCache.php:259 Stack trace: ....

Guess I need to check some more on the memcache configuration, will keep you updated.

oh, I got it now, my understanding of memcache as a build in service of php was just all wrong :slight_smile:

Memcached is a service that needs to be installed and startet before php can use ist.

On CentOS I used:

yum install memcached.x86_64

and voila, it works now :wink:

The output of phpInfo simply indicated that the extension to speak to a memcached server is installed and enabled, does not mean the server itself is installed or running.

Hope this helps some other people and saves some time troubleshooting.