openclassrooms / cache-bundle
Symfony2 Bundle for OpenClassrooms Cache
v2.2.1
2024-08-05 15:16 UTC
Requires
- php: >=8.2
- openclassrooms/cache: ^v1.1.0
- symfony/config: ~5.4 || ~6.4 || ~v7.1
- symfony/dependency-injection: ~5.4 || ~6.4 || ~v7.1
- symfony/http-kernel: ~5.4 || ~6.4 || ~v7.1
Requires (Dev)
- phpunit/phpunit: ~9.6
This package is auto-updated.
Last update: 2024-09-06 14:18:51 UTC
README
CacheBundle 为 Doctrine Cache 实现添加功能
- 默认生命周期
- 使用命名空间进行获取
- 使用命名空间进行保存
- 通过命名空间策略进行缓存失效
- 缓存提供者构建器
更多详情请参见 OpenClassrooms/Cache.
安装
可以使用 composer 安装此包
composer require openclassrooms/cache-bundle
或者直接将包添加到 composer.json 文件中。
{ "require": { "openclassrooms/cache-bundle": "*" } }
安装包之后,将包添加到 AppKernel.php 文件中
// in AppKernel::registerBundles() $bundles = array( // ... new OpenClassrooms\Bundle\CacheBundle\OpenClassroomsCacheBundle(), // ... );
配置
open_classrooms_cache: default_lifetime: 10 (optional, default = 0) # Providers # array provider: array # redis provider: redis: host: localhost port: 6379 (optional, default = 6379) timeout: 0.0 (optional, default = 0.0)
使用方法
配置的缓存可通过 openclassrooms.cache.cache
服务访问
$cache = $container->get('openclassrooms.cache.cache'); $cache->fetch($id); $cache->fetchWithNamespace($id, $namespaceId); $cache->save($id, $data); $cache->saveWithNamespace($id, $data, $namespaceId); $cache->invalidate($namespaceId);
配置的缓存提供者可通过 openclassrooms.cache.cache_provider
服务访问
$cacheProvider = $container->get('openclassrooms.cache.cache_provider');
缓存提供者构建器可通过 openclassrooms.cache.cache_provider
服务访问
$builder = $container->get('openclassrooms.cache.cache_provider_builder'); // Redis $cacheProvider = $builder ->create(CacheProviderType::REDIS) ->withHost('127.0.0.1') ->withPort(6379) // Default 6379 ->withTimeout(0.0) // Default 0.0 ->build();
更多详情请参见 OpenClassrooms/Cache.