dotkernel / dot-cache
扩展 symfony-cache 的 DotKernel 缓存组件
Requires
- php: ~8.2.0 || ~8.3.0
- symfony/cache: ^7.0
Requires (Dev)
- laminas/laminas-coding-standard: ^2.5
- phpunit/phpunit: ^10.5.5
- squizlabs/php_codesniffer: ^3.8.0
- vimeo/psalm: ^5.13
README
重要
dot-cache 是 symfony/cache 的包装器
dot-cache 徽章
注意
此包仅支持
array
和filesystem
适配器,您可以同时使用多个适配器。
安装
在您的项目目录中运行以下命令
composer require dotkernel/dot-cache
安装后,将 Dot\Cache\ConfigProvider::class
类添加到您的配置聚合中。
Doctrine in_array 配置
在 config\autoload\doctrine.global.php
中,您需要添加以下配置
在 doctrine.configuration.orm_default
键下添加以下配置
'result_cache' => 'array',
'metadata_cache' => 'array',
'query_cache' => 'array',
'hydration_cache' => 'array',
'second_level_cache' => [
'enabled' => true,
'default_lifetime' => 3600,
'default_lock_lifetime' => 60,
'file_lock_region_directory' => '',
'regions' => [],
],
接下来,在 doctrine
键下添加以下配置
'cache' => [
'array' => [
'class' => \Dot\Cache\Adapter\ArrayAdapter::class,
],
],
注意
上述配置将使用内存缓存,因为您使用了
array
适配器。
如果您想将缓存存储在本地磁盘上的文件中,您需要使用 filesystem
适配器。
使用文件系统配置 Doctrine 缓存
filesystem
适配器需要一些额外的配置
-
目录(文件夹路径)
-
命名空间(目录名称)
'cache' => [ 'array' => [ 'class' => \Dot\Cache\Adapter\ArrayAdapter::class, ], 'filesystem' => [ 'class' => \Dot\Cache\Adapter\FilesystemAdapter::class, 'directory' => getcwd() . '/data/cache', 'namespace' => 'doctrine', ], ],
您可以使用 filesystem
适配器将 result_cache
、metadata_cache
、query_cache
、hydration_cache
存储到文件中,或者您可以使用 array
适配器将 result_cache
存储到内存中。
内存和文件系统适配器的配置示例
config\autoload\doctrine.global.php
文件的配置示例
return [
'dependencies' => [
'factories' => [
\Dot\Cache\Adapter\FilesystemAdapter::class => \Dot\Cache\Factory\FilesystemAdapterFactory::class,
'aliases' => [
\Symfony\Component\Cache\Adapter\FilesystemAdapter::class => \Dot\Cache\Adapter\FilesystemAdapter::class
],
],
'doctrine' => [
'configuration' => [
'orm_default' => [
'result_cache' => 'array',
'metadata_cache' => 'array',
'query_cache' => 'filesystem',
'hydration_cache' => 'array',
'second_level_cache' => [
'enabled' => true,
'default_lifetime' => 3600,
'default_lock_lifetime' => 60,
'file_lock_region_directory' => '',
'regions' => [],
],
],
],
'cache' => [
'array' => [
'class' => \Symfony\Component\Cache\Adapter\ArrayAdapter::class,
],
'filesystem' => [
'class' => \Dot\Cache\Adapter\FilesystemAdapter::class,
'directory' => getcwd() . '/data/cache',
'namespace' => 'doctrine',
],
],
],
];
注意
上述配置只是一个示例,不应直接使用。
您可以使用 doctrine.configuration.orm_default.second_level_cache.enabled
键启用/禁用缓存系统。