szmnmichalowski / doctrine-cache-toolbar
在ZendDeveloperTools上显示的二级缓存的统计信息
1.0.0
2017-03-25 13:26 UTC
Requires
- php: ^5.6 || ^7.0
- doctrine/doctrine-orm-module: 1.1.1
- zendframework/zend-developer-tools: ^1.0.0 || ^1.1.0
Requires (Dev)
- container-interop/container-interop: ^1.1
- phpunit/phpunit: ^4.0 || ^5.0
- zendframework/zend-test: ^2.5
This package is not auto-updated.
Last update: 2024-09-28 19:58:22 UTC
README
DoctrineCacheToolbar是一个与Zend Framework 2/3集成的Doctrine 2模块。
当在doctrine的配置中启用了二级缓存时,它会显示区域的统计信息。
安装
您可以通过将此项目克隆到您的./vendor/目录中或使用composer(更推荐)来安装此模块。
1. 将此项目添加到您的composer.json中
"require": {
"szmnmichalowski/doctrine-cache-toolbar": "dev-master"
}
2. 更新您的依赖关系
$ php composer.phar update
3. 将模块添加到您的application.config.php中。它需要DoctrineModule,DoctrineORMModule和ZendDeveloperTools。
return array(
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'ZendDeveloperTools',
'DoctrineCacheToolbar' // <- Add this line
)
);
使用方法
此模块无需任何配置即可工作。如果您启用了二级缓存,它将显示缓存区域的统计信息。
什么是二级缓存?
二级缓存是 Doctrine 2.5 版本中添加的 Doctrine 功能。它允许缓存实体及其关联。更多信息可以在 Doctrine 的网站上找到http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html
如何在 Zend Framework 2/3 中配置二级缓存?
将以下代码添加到 Doctrine 的配置文件中
'doctrine' => [
'configuration' => [
'orm_default' => [
'metadata_cache' => 'filesystem', // name of cache adapter
'query_cache' => 'filesystem', // name of cache adapter
'result_cache' => 'filesystem', // name of cache adapter
'hydration_cache' => 'filesystem', // name of cache adapter
'second_level_cache' => [
'enabled' => true,
'default_lifetime' => 300,
'default_lock_lifetime' => 300,
'file_lock_region_directory' => __DIR__.'../../data/cache',
]
]
]
]
您也可以为每个区域定义区域和寿命。在 second_level_cache 指数内添加以下数组
'regions' => [
'my_region_name' => [
'lifetime' => 100,
'lock_lifetime' => 200
],
]
然后,在您的实体中添加
namespace Application\Entity;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Table(name="app_post")
* @ORM\Cache("NONSTRICT_READ_WRITE", region="my_region_name")
*/
class Post
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=40, nullable=false)
*/
private $title;
}
从现在起,工具栏应显示类似于上面图像中的统计信息。