doctrine/phpcr-dbal-symfony-pack
Install the package via Composer:
composer require vendor/package-name
Register the service provider in config/app.php under providers:
Vendor\PackageName\PackageServiceProvider::class,
Publish the config file (if available) with:
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider" --tag="config"
For first use, initialize caching (if applicable) by running:
php artisan cache:clear
Check the updated config/package-name.php for new Symfony Cache configuration options (e.g., cache_driver, cache_prefix).
Leverage Symfony Cache’s drivers (e.g., array, apcu, redis, file) via the updated config:
// config/package-name.php
'cache' => [
'driver' => env('CACHE_DRIVER', 'redis'),
'prefix' => 'package_',
],
Use the package’s cache helpers (if provided) to interact with Symfony Cache:
use Vendor\PackageName\Facades\CacheHelper;
// Store data
CacheHelper::put('key', 'value', now()->addHour());
// Retrieve data
$data = CacheHelper::get('key');
Inject the cache instance directly into your services:
use Symfony\Component\Cache\CacheInterface;
class MyService {
public function __construct(private CacheInterface $cache) {}
public function doSomething() {
$this->cache->get('key', fn() => $this->expensiveOperation());
}
}
Replace old Doctrine Cache calls (e.g., Doctrine\Common\Cache\CacheProvider) with Symfony Cache equivalents:
// Old (deprecated)
$cache = new Doctrine\Common\Cache\FilesystemCache();
// New
$cache = new Symfony\Component\Cache\Adapter\FilesystemAdapter();
doctrine/cache-bundle. Update any direct dependencies on it.CacheInterface differs slightly from Doctrine’s. Review method signatures (e.g., fetch() vs get()).
get() with a fallback closure for missing keys:
$value = $cache->get('key', fn() => $defaultValue);
CACHE_DRIVER in .env matches Symfony’s supported drivers (e.g., redis, file).
CACHE_DRIVER=redis
CACHE_CONNECTION=default
cache_prefix in config to avoid key clashes with other packages.$cache->get('key', fn() => $data)->tag('user-data');
$cache->invalidateTags(['user-data']);
config/cache.php:
'stores' => [
'redis' => [
'driver' => 'redis',
'connection' => 'cache',
'options' => [
'prefix' => 'package_',
'pool' => true, // Enable connection pooling
],
],
],
config/cache.php:
'default' => env('CACHE_DRIVER', 'array'),
'stores' => [
'array' => [
'driver' => 'array',
'debug' => env('APP_DEBUG', false), // Log misses
],
],
$cache = new Symfony\Component\Cache\Adapter\FilesystemAdapter(
new Symfony\Component\Cache\Adapter\FilesystemCacheItemPool('/path/to/cache'),
[],
new Symfony\Component\Cache\Psr16Adapter(new Monolog\Logger('cache'))
);
Symfony\Component\Cache\CacheItemPoolInterface for specialized storage:
class CustomCachePool implements CacheItemPoolInterface {
// Implement required methods
}
CacheWarmerInterface to preload critical data:
class PackageCacheWarmer implements CacheWarmerInterface {
public function warmUp($cacheDir) {
$cache = new Symfony\Component\Cache\Adapter\FilesystemAdapter(
new Symfony\Component\Cache\Adapter\FilesystemCacheItemPool($cacheDir)
);
$cache->get('preload-key', fn() => $this->preloadData());
}
}
How can I help you explore Laravel packages today?