cache/doctrine-adapter
PSR-6 cache pool adapter backed by Doctrine Cache. Wraps Doctrine cache drivers (e.g., MemcachedCache) in a standards-compliant PSR-6 CacheItemPool for easy integration with php-cache features like tagging and hierarchy support.
Illuminate\Cache\Repository), enabling seamless integration with Laravel’s caching middleware, Eloquent, and API responses. The adapter’s PSR-6 compliance ensures compatibility with Laravel’s built-in cache abstractions without requiring low-level changes.MemcachedCache, RedisCache) for ORM operations. Eliminates duplication by reusing existing Doctrine cache infrastructure for PSR-6 use cases.Cache::tags() and Cache::forgetTags() methods. Critical for granular invalidation in read-heavy applications (e.g., e-commerce product caches, user profiles).config/cache.php with minimal configuration. Example:
'doctrine_memcached' => [
'driver' => 'doctrine',
'key' => env('CACHE_DOCTRINE_KEY'),
'store' => Cache\Adapter\Doctrine\DoctrineCachePool::class,
'options' => [
'doctrine_cache' => new \Doctrine\Common\Cache\MemcachedCache(new \Memcached()),
],
],
doctrine/cache as a dependency, which may introduce version conflicts with other Doctrine packages (e.g., doctrine/dbal). Use explicit version constraints in composer.json to mitigate risks.CacheResponseMiddleware), enabling HTTP caching without additional setup.{}()/@:`. Laravel’s Eloquent or custom cache key generation may produce invalid keys, requiring sanitization or custom key prefixes.model:123) include restricted characters. Requires proactive key sanitization or prefixing.Cache::tags() behavior (e.g., wildcard support, bulk operations). Rigorous testing is required to validate invalidation workflows.memcached, redis) to confirm performance parity.symfony/cache if the adapter becomes unsustainable).memcached, redis)? (e.g., existing Doctrine dependency, specific tagging requirements).model:123) be sanitized to comply with PSR-6 constraints?Cache::forgetTags(['users']))?file driver or return cached data despite errors)?symfony/cache).Illuminate\Cache\Repository, enabling use with Cache::put(), Cache::remember(), and Cache::tags().CacheResponseMiddleware for HTTP caching.remember(), tags()).doctrine/cache). Avoids reinventing caching logic if Doctrine is already a dependency.php-cache/psr6-adapters for other backends (e.g., Redis, Memcached).composer require cache/doctrine-adapter doctrine/cache
doctrine/cache:^1.11).config/cache.php to include the new driver:
'doctrine_memcached' => [
'driver' => 'doctrine',
'key' => env('CACHE_DOCTRINE_KEY', 'default'),
'store' => Cache\Adapter\Doctrine\DoctrineCachePool::class,
'options' => [
'doctrine_cache' => new \Doctrine\Common\Cache\MemcachedCache(new \Memcached()),
],
],
function sanitizeCacheKey(string $key): string {
return Str::of($key)->replaceMatched('/[{}()\/\\@:]/', '_')->toString();
}
Cache::tags(['users'])->put('user:1', $data);
Cache::forgetTags(['users']); // Should invalidate via Doctrine.
php artisan cache:clear + synthetic load tests.config/cache.php:
'stores' => [
'doctrine_memcached' => [
'driver' => 'doctrine',
'fallback' => 'file', // Fallback to file driver if Doctrine fails.
],
],
doctrine/cache v1.11+. Check for conflicts with other Doctrine packages (e.g., doctrine/dbal).file) with the Doctrine adapter in staging.memcached, redis) in a feature flagged environment.CacheResponseMiddleware).doctrine/cache and cache/doctrine-adapter for updates using:
composer why-not cache/doctrine-adapter
composer.json to avoid unexpected updates:
"require": {
"doctrine/cache": "^1.11",
"cache/doctrine-adapter": "^1.2"
}
How can I help you explore Laravel packages today?