The information about the database schema that's needed for ORM comes from Schema that retrieves it from the database server.
For faster access, Schema stores database schema information in SchemaCache.
When the Schema needs retrieve information about the database schema, it first checks the cache.
You can configure SchemaCache to use PSR-16 cache implementation in two ways:
- Use DI container autowiring.
- Configure it manually.
Examples below use yiisoft/cache. Make sure you have installed it via Composer
using composer require yiisoft/cache
.
This configuration is suitable if you want to use the same cache driver for the whole application.
Create a file config/common/di/cache.php
for cache:
use Psr\SimpleCache\CacheInterface;
use Yiisoft\Cache\File\FileCache;
/** @var array $params */
return [
CacheInterface::class => [
'class' => FileCache::class,
'__construct()' => [
'cachePath' => __DIR__ . '/../../runtime/cache',
],
],
];
The SchemaCache
requires CacheInterface
and DI container will automatically resolve it.
This configuration is suitable if you want to use a different cache driver for caching schema.
Create a file config/common/di/db-schema-cache.php
for cache:
use Yiisoft\Cache\File\FileCache;
use Yiisoft\Db\Cache\SchemaCache;
return [
SchemaCache::class => [
'class' => SchemaCache::class,
'__construct()' => [
new FileCache(__DIR__ . '/../../runtime/cache'),
],
],
];