doctrine/cache
Doctrine Cache is a legacy cache component extracted from Doctrine Common, offering multiple cache drivers and interfaces used across Doctrine projects. Note: the library is deprecated and no longer maintained; prefer a PSR-6 or PSR-16 cache instead.
Start by installing via Composer: composer require doctrine/cache. Then, choose a cache driver and instantiate it — for example, ArrayCache for development or RedisCache for production. Wrap your expensive operations with fetch() or save() to cache results. A minimal example:
use Doctrine\Common\Cache\FilesystemCache;
$cache = new FilesystemCache('/path/to/cache/dir');
$result = $cache->fetch('my_key') ?: $cache->save('my_key', expensiveComputation(), 3600);
First place to look: the CacheProvider abstract class and concrete driver classes (e.g., ArrayCache, RedisCache) in the Doctrine\Common\Cache namespace. Use fetch() for safe retrieval (returns null on miss) and save() with TTL — avoid contains() before fetch() unless needed for logic branching.
UserRepository::findCachedBy($id) → 'user:' . $id).setNamespace() (e.g., setNamespace('myapp_v1_')) to isolate cache entries per environment or version — prevents stale data when upgrading.'products:by_category:' . $categoryId) and clear entries via deleteMultiple() or key iteration (if driver supports it).Cache::store('file'), redis, etc., via illuminate/cache adapters. You can plug it into Symfony or standalone apps using PSR-6 bridge adapters if needed.Logger decorator.deleteMultiple(glob($cacheDir . 'products:*')) for filesystem).delete() vs deleteMultiple(): delete() on many keys one-by-one is slow — batch deletes where possible (e.g., store key list in a master entry and delete both).DoctrineCommonCachePSR16Adapter (if available) or modern packages like psr/cache directly for new code — Doctrine Cache is in maintenance mode (last release 2022).How can I help you explore Laravel packages today?