openclassrooms / doctrine-cache-extension-bundle
Symfony2 Bundle 扩展 doctrine 缓存功能
v2.0.1
2022-03-15 10:46 UTC
Requires
- php: >=7.1
- doctrine/doctrine-cache-bundle: ~1.3
- openclassrooms/doctrine-cache-extension: 1.0.*@dev
- symfony/config: ~3.4 || ~4.0
- symfony/dependency-injection: ~3.4 || ~4.0
- symfony/http-kernel: ~3.4 || ~4.0
- symfony/stopwatch: ~3.4 || ~4.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-15 16:03:26 UTC
README
DoctrineCacheExtensionBundle 提供了 DoctrineCacheExtension 库的集成。DoctrineCacheExtension 提供了处理缓存管理的功能
- 默认生命周期
- 使用命名空间获取
- 使用命名空间保存
- 通过命名空间策略进行缓存失效
- 在分析器中可用的数据收集器(尚未实现)
有关更多详细信息,请参阅 OpenClassrooms/DoctrineCacheExtension。
安装
可以使用 composer 安装此包
composer require openclassrooms/doctrine-cache-extension-bundle
或直接将其添加到 composer.json 文件中。
{ "require": { "openclassrooms/doctrine-cache-extension-bundle": "*" } }
安装包后,将包和 DoctrineCacheBundle 添加到 AppKernel.php 文件中
// in AppKernel::registerBundles() $bundles = [ // ... new new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(); new OpenClassrooms\Bundle\DoctrineCacheExtensionBundle\OpenClassroomsDoctrineCacheExtensionBundle(), // ... )];
配置
# app/config/config.yml doctrine_cache_extension: default_lifetime: 10 #optional, default = 0
要配置缓存提供者,请使用 DoctrineCacheBundle 配置。例如
# app/config/config.yml doctrine_cache: providers: a_cache_provider: type: array
用法
$cache = $container->get('doctrine_cache.providers.a_cache_provider'); $cache->fetch($id); $cache->fetchWithNamespace($id, $namespaceId); $cache->save($id, $data); $cache->saveWithNamespace($id, $data, $namespaceId); $cache->invalidate($namespaceId);
分析器
该包在分析器中提供数据,例如调用次数、调用类型等。(图片)