openclassrooms / cache-bundle
Symfony2 Bundle for OpenClassrooms Cache
Installs: 394 909
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 25
Forks: 1
Open Issues: 1
Type:symfony-bundle
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: 2025-01-06 15:07:09 UTC
README
CacheBundle adds features to Doctrine Cache implementation
- Default lifetime
- Fetch with a namespace
- Save with a namespace
- Cache invalidation through namespace strategy
- CacheProvider Builder
See OpenClassrooms/Cache for more details.
Installation
This bundle can be installed using composer:
composer require openclassrooms/cache-bundle
or by adding the package to the composer.json file directly.
{ "require": { "openclassrooms/cache-bundle": "*" } }
After the package has been installed, add the bundle to the AppKernel.php file:
// in AppKernel::registerBundles() $bundles = array( // ... new OpenClassrooms\Bundle\CacheBundle\OpenClassroomsCacheBundle(), // ... );
Configuration
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)
Usage
The configured cache is available as openclassrooms.cache.cache
service:
$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);
The configured cache provider is available as openclassrooms.cache.cache_provider
service:
$cacheProvider = $container->get('openclassrooms.cache.cache_provider');
The cache provider builder is available as openclassrooms.cache.cache_provider
service:
$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();
See OpenClassrooms/Cache for more details.