ibexa/http-cache package is designed for HTTP-level caching (primarily Varnish integration) within the Ibexa DXP ecosystem, leveraging Symfony’s HTTP cache layer. For a Laravel-based application, this package introduces Symfony-specific abstractions (e.g., HttpCache, Varnish, Purger) that may require adaptation to Laravel’s ecosystem (e.g., Symfony Bridge, PSR-15 middleware).HttpCache middleware, which can be ported to Laravel via middleware wrappers (e.g., Illuminate\Pipeline).HttpFoundation, Cache). Mitigation: Use Laravel’s Symfony Bridge (symfony/http-foundation, symfony/cache) or custom adapters.ezpublish:content:update), which can be mapped to Laravel’s cache tags or custom event listeners.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Symfony Dependency | Laravel lacks native Symfony HTTP cache integration. | Use spatie/laravel-symfony-support or build a PSR-15 middleware wrapper. |
| Varnish Integration | VCL templates assume Ibexa’s routing; Laravel’s routes may differ. | Abstract Varnish logic into configurable middleware or use Laravel Forge/Envoyer for Varnish. |
| PHP 8.3 Requirement | Laravel 10+ supports PHP 8.3, but older versions may not. | Enforce PHP 8.3+ in CI/CD or provide backward-compatible shims. |
| Cache Tagging | Laravel’s cache tags (Illuminate\Cache) differ from Symfony’s TaggableResponse. |
Create a unified cache tagging interface (e.g., CacheTaggerContract). |
| Testing Complexity | Varnish testing requires mocking HTTP responses; Laravel’s HTTP tests may need extensions. | Use pestphp/pest-plugin-laravel-http + Varnish Docker containers for integration tests. |
Symfony Compatibility:
HttpCache middleware without performance loss?spatie/laravel-cache-control) that offer similar functionality with lower risk?Varnish Strategy:
VarnishPurger) or externally configured (e.g., Ansible/Envoyer)?php artisan route:cache) interact with Varnish tags?Cache Invalidation:
ModelObserver) trigger Symfony-style cache invalidation?Performance Impact:
HttpCache vs. Laravel’s native caching?Licensing:
spatie/laravel-cache-control) that avoid proprietary licensing?spatie/laravel-symfony-support to integrate HttpFoundation, Cache, and HttpClient.HttpCache to Laravel middleware using Closure-based pipelines.Illuminate\Routing\Middleware to intercept requests/responses for cache logic.Varnish class to work with Laravel’s Request/Response objects.Cache component).array driver (requires Symfony’s ArrayAdapter).Phase 1: Dependency Setup
composer require symfony/http-foundation symfony/cache symfony/http-client
composer require spatie/laravel-symfony-support
Phase 2: Core Integration
HttpCache middleware:
// app/Http/Middleware/HttpCache.php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
class HttpCacheMiddleware
{
public function handle(Request $request, Closure $next): Response
{
$symfonyRequest = new SymfonyRequest($request);
$symfonyResponse = $next($symfonyRequest);
$laravelResponse = new SymfonyResponse($symfonyResponse);
return $laravelResponse;
}
}
app/Http/Kernel.php:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\HttpCache::class,
// ...
],
];
Phase 3: Varnish Configuration
ibexa/http-cache/src/Varnish to work with Laravel’s Request:
// app/Services/VarnishPurger.php
use Ibexa\HttpCache\Varnish;
class VarnishPurger extends Varnish
{
public function purgeTags(array $tags): void
{
// Adapt to Laravel's HTTP client
Http::post('http://varnish/purge', ['tags' => $tags]);
}
}
Http client to purge:
Http::post('http://varnish/purge', ['url' => '/path/to/invalidate']);
Phase 4: Cache Invalidation
eloquent.updated) to trigger Symfony-style invalidation:
// app/Providers/EventServiceProvider.php
public function boot(): void
{
Model::updated(function ($model) {
app(VarnishPurger::class)->purgeTags(['content:'.$model->id]);
});
}
| Component | Laravel Equivalent | Compatibility Notes |
|---|---|---|
Symfony\Component\HttpFoundation\Request |
Illuminate\Http\Request |
Use spatie/laravel-symfony-support for conversion. |
Symfony\Component\HttpFoundation\Response |
Illuminate\Http\Response |
Convert via SymfonyResponse wrapper. |
Symfony\Component\HttpKernel\HttpCache |
Custom Middleware | Reimplement logic in Laravel’s pipeline. |
Ibexa\HttpCache\Purger |
Custom Service | Extend to use Laravel’s Http client or queue system. |
| Varnish VCL | External Config | Requires separate Varnish deployment or middleware-based purging. |
How can I help you explore Laravel packages today?