ezsystems/ezplatform-http-cache
Symfony bundle providing advanced HTTP cache handling for Ibexa DXP (formerly eZ Platform). Adds caching features and tooling to improve performance and cache control. Intended for use within an Ibexa DXP installation.
Installation:
composer require ezsystems/ezplatform-http-cache
Ensure you have Ibexa DXP installed as a dependency.
Enable the Bundle:
Add to config/bundles.php:
return [
// ...
Ibexa\HttpCacheBundle\IbexaHttpCacheBundle::class => ['all' => true],
];
Configure Varnish (Example):
Update config/packages/ibexa_http_cache.yaml:
ibexa_http_cache:
varnish:
host: '127.0.0.1'
port: 6081
purge_url: 'http://127.0.0.1:6082/purge'
purge:
enabled: true
tags: ['content', 'user']
First Use Case: Trigger cache invalidation after content updates:
use Ibexa\HttpCacheBundle\Purger\TagPurger;
// In a service or controller
$tagPurger = $this->container->get('ibexa.http_cache.purger.tag');
$tagPurger->purge(['content/123']); // Purge cache for content ID 123
Cache Invalidation:
TagPurger to invalidate cache for specific content or tags:
$tagPurger->purge(['content/456', 'user/789']);
UrlPurger for URL-based invalidation:
$urlPurger = $this->container->get('ibexa.http_cache.purger.url');
$urlPurger->purge(['/content/123', '/content/456']);
Vary Headers:
VaryHeaderListener to handle dynamic content (e.g., language, user roles):
# config/packages/ibexa_http_cache.yaml
ibexa_http_cache:
vary:
headers:
- 'Accept-Language'
- 'X-Ibexa-User-Role'
Conditional Logic:
ConditionalRemoveVaryHeaderListener to exclude headers for specific routes:
// src/EventListener/CustomVaryHeaderListener.php
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($request->getPathInfo() === '/admin') {
$event->getResponse()->headers->remove('Vary');
}
}
Edge-Side Includes (ESI):
ESI tags in templates to cache fragments:
{# templates/content.html.twig #}
{% esi 'content-block' %}
kernel.response to modify responses before caching:
$eventDispatcher->addListener(
KernelEvents::RESPONSE,
[$this, 'onKernelResponse']
);
# config/packages/ibexa_http_cache.yaml
ibexa_http_cache:
exclude:
paths:
- '^/api/'
HttpCacheTestTrait for unit tests:
use Ibexa\HttpCacheBundle\Tests\Integration\HttpCacheTestTrait;
class MyTest extends WebTestCase
{
use HttpCacheTestTrait;
}
Varnish Configuration:
Varnish is configured to respect Surrogate-Control headers. Misconfigurations may lead to stale cache.varnishlog to inspect cache hits/misses:
varnishlog -g request -q 'ReqUrl eq "/content/123"'
Tag vs. URL Purges:
Header Conflicts:
Cache-Control and Surrogate-Control headers. Use Surrogate-Control for Varnish-specific directives:
$response->headers->set('Surrogate-Control', 'content="stale-while-revalidate=60"');
ESI Edge Cases:
curl -H "X-ESI: 1" to simulate edge-side includes.# config/packages/monolog.yaml
handlers:
ibexa_http_cache:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.ibexa_http_cache.log"
level: debug
curl -I to check X-Ibexa-Cache headers:
curl -I http://your-site.com/content/123
X-Ibexa-Cache: HIT
Surrogate-Control: content="stale-while-revalidate=60"
Custom Purge Strategies:
PurgerInterface for custom invalidation logic:
class CustomPurger implements PurgerInterface
{
public function purge(array $tags): void
{
// Custom logic (e.g., Redis, CDN API)
}
}
services:
App\Purger\CustomPurger:
tags: ['ibexa.http_cache.purger']
Dynamic Vary Headers:
VaryHeaderListener to add runtime headers:
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$event->getResponse()->headers->addCacheControlDirective(
'private',
$request->get('user') ? 'user=' . $request->get('user') : null
);
}
Cache Warmup:
HttpClient:
$client = $this->container->get('http_client');
$client->request('GET', '/content/123', [
'headers' => ['X-Ibexa-Warmup' => '1'],
]);
60 seconds for stale-while-revalidate by default. Adjust in config/packages/ibexa_http_cache.yaml:
ibexa_http_cache:
default_ttl: 300 # 5 minutes
content/123, not content#123). Use hyphens for multi-word tags:
$tagPurger->purge(['content/home-page', 'user/editor']);
How can I help you explore Laravel packages today?