Installation:
composer require cache/cache-bundle
Add to config/bundles.php:
return [
// ...
Cache\CacheBundle\CacheBundle::class => ['all' => true],
];
Configure PSR-6 Cache Pool:
Define your cache pool (e.g., cache.yaml):
framework:
cache:
pools:
my_cache_pool.app:
adapter: cache.adapter.filesystem
provider: 'ocramius.file_cache.provider'
directory: '%kernel.cache_dir%/my_cache'
First Use Case: Cache Doctrine metadata (most common entry point):
# config/packages/doctrine.yaml
doctrine:
orm:
metadata_cache_driver: cache.pool.my_cache_pool.app.metadata
query_cache_driver: cache.pool.my_cache_pool.app.query
result_cache_driver: cache.pool.my_cache_pool.app.result
Doctrine Integration:
doctrine.yaml.query_cache_driver: cache.pool.my_cache_pool.app.query
Session Caching:
framework.yaml:
framework:
session:
handler_id: cache.session.handler
cache.session.handler.Routing Cache:
framework:
router:
cache_pool: cache.pool.my_cache_pool.app.routes
Custom Services:
use Psr\Cache\CacheItemPoolInterface;
class MyService {
public function __construct(private CacheItemPoolInterface $cache) {}
}
%kernel.environment% in pool names (e.g., cache.pool.dev.app vs. cache.pool.prod.app).cache_item->setTag('user_123')).Pool Configuration:
framework.cache.pools.ServiceNotFoundException.Doctrine Cache Drivers:
cache.pool.my_cache_pool.app.metadata).Session Caching:
cache.session.handler).session.handler.native_file) won’t work.Debugging:
bin/console debug:cache to list registered pools.Cache Warmup:
bin/console cache:warmup
Tag-Based Invalidation:
$this->cache->invalidateTags(['user_123']);
Environment Awareness:
%kernel.debug% to disable caching in dev:
pools:
my_cache_pool.app:
adapter: cache.adapter.null # Disabled in dev
Extending the Bundle:
cache.pool.my_custom_pool in a custom bundle’s Resources/config/services.yaml.Performance:
bin/console debug:cache and adjust directory paths.cache.adapter.redis or cache.adapter.apcu.How can I help you explore Laravel packages today?