Cms: yii\caching\DbCache is incompatible with craft\db\Command

Created on 3 Apr 2020  路  2Comments  路  Source: craftcms/cms

Description

If you create a cache table as specified by the yii\caching\DbCache::$cacheTable docs, and configure your cache component to use yii\caching\DbCache, you will get SQL errors about missing dateCreated, dateUpdated and uid columns.

That happens because craft\db\Command::upsert() and insert() (which yii\caching\DbCache uses) assume that these columns exist, as they do for the vast majority of Craft鈥檚 database tables.

These errors can be worked around by adding those three columns to the cache table, in addition to the columns Yii requires, however they serve no purpose and actually may slow database caching down, so that鈥檚 not a great solution.

Instead we should provide our own DbCache class, which extends Yii鈥檚 and overrides its setValue() and addValue() methods, making them compatible with craft\db\Command by passing false to the $includeAuditColumns argument on upsert() and insert().

Additional info

  • Craft version: 3.4.13
bug minor

Most helpful comment

This is now resolved for the next release (3.4.14).

Going forward you will be able to set the cache component to a new craft\cache\DbCache class, which is fully compatible with craft\db\Command.

// -- config/app.php --
return [
    'components' => [
        'cache' => craft\cache\DbCache::class,
    ],
];

Also added a new setup/db-cache-table command, which can be run to quickly create the cache table as specified by yii\cachingDbCache::$cacheTable.

All 2 comments

This is now resolved for the next release (3.4.14).

Going forward you will be able to set the cache component to a new craft\cache\DbCache class, which is fully compatible with craft\db\Command.

// -- config/app.php --
return [
    'components' => [
        'cache' => craft\cache\DbCache::class,
    ],
];

Also added a new setup/db-cache-table command, which can be run to quickly create the cache table as specified by yii\cachingDbCache::$cacheTable.

Craft 3.4.14 is out with this change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelhue picture michaelhue  路  3Comments

timkelty picture timkelty  路  3Comments

angrybrad picture angrybrad  路  3Comments

mccombs picture mccombs  路  3Comments

davist11 picture davist11  路  3Comments