alengo / sulu-http-cache-bundle
HTTP cache helpers for Sulu/Symfony: strip tracking query parameters and store CTA marketing-attribution cookies at the reverse-proxy layer.
Package info
github.com/alengodev/SuluHttpCacheBundle
Type:symfony-bundle
pkg:composer/alengo/sulu-http-cache-bundle
Requires
- php: ^8.2
- friendsofsymfony/http-cache: ^3.0
- guzzlehttp/promises: ^3.2
- nyholm/psr7: ^1.8
- symfony/config: ^7.2 || ^8.0
- symfony/dependency-injection: ^7.2 || ^8.0
- symfony/event-dispatcher: ^7.2 || ^8.0
- symfony/http-client: ^7.4 || ^8.0
- symfony/http-foundation: ^7.2 || ^8.0
- symfony/http-kernel: ^7.2 || ^8.0
- symfony/yaml: ^7.2 || ^8.0
Requires (Dev)
- php-cs-fixer/shim: ^3.93
- phpunit/phpunit: ^11.5 || ^12.0
- rector/rector: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
HTTP-cache helpers for Sulu / Symfony, wired onto the FOS EventDispatchingHttpCache
(reverse-proxy) kernel:
- StripQueryParametersSubscriber — removes tracking query parameters (
utm_*,gclid,fbclid, …) atPRE_HANDLE, before the cache key is computed, so tracking-param URL permutations collapse onto a single cache entry. - CtaInterestsSubscriber — stores matched tracking parameters in a cookie (default
cta_interests) for marketing attribution. - CtaRefererSubscriber — stores an external referer in a cookie (default
cta_referer).
The CTA cookies are written in POST_HANDLE (after the store decision) so they are set per
response and never baked into a cached page.
Installation
composer require alengo/sulu-http-cache-bundle
Register the bundle (Symfony Flex does this automatically):
// config/bundles.php Alengo\SuluHttpCacheBundle\AlengoHttpCacheBundle::class => ['all' => true],
Wiring
The subscribers run on the reverse-proxy cache kernel, which is created in the front
controller / Kernel::getHttpCache() before the DI container is available. Wire them with
the provided configurator:
use Alengo\SuluHttpCacheBundle\Cache\CacheKernelConfigurator; public function getHttpCache(): HttpKernelInterface { if (!$this->httpCache instanceof HttpKernelInterface) { $cache = new SuluHttpCache($this); (new CacheKernelConfigurator())->configure( $cache->getEventDispatcher(), $this->getProjectDir(), $this->getEnvironment(), ); $this->httpCache = $cache; } return $this->httpCache; }
Configuration
All settings live in config/packages/alengo_http_cache.yaml. The configurator reads this
file directly at runtime (no container), so keep the values inline — cross-file imports and
%env()% placeholders are not resolved. Defaults are applied for anything omitted.
alengo_http_cache: strip_query_parameters: enabled: true # deny_list: ['utm_[a-z]+', 'gclid', ...] # defaults to the built-in tracking list # allow_list: [] # path_allow_list: {} # path regex => parameter patterns kept on matching paths cta_interests: enabled: true cookie_name: cta_interests # allow_list: [...] # defaults to the built-in tracking list cta_referer: enabled: true cookie_name: cta_referer
Allow-list mode (strip every unknown parameter)
With the deny list only known tracking parameters are removed: any other parameter (?x=1, ?x=2, …) still becomes
part of the cache key, so every random value means a new cache entry and a full render. An empty deny list removes
every parameter, except those kept by
allow_list: parameter-name patterns kept on every path,path_allow_list: a path regex (matched against the path info, brace delimiters like Symfony routes, so{2}and#need no escaping) => the parameter-name patterns kept on matching paths. Patterns of all matching paths are combined;.*keeps every parameter of a path (e.g. endpoints that are never cached, like an OAuth authorize route).
alengo_http_cache: strip_query_parameters: deny_list: [] path_allow_list: '^/[a-z]{2}/search(\.[a-z]+)?$': ['q'] # the search term on the search page only '^/media/[0-9]+/download/': ['v', 'inline'] # media downloads '^/authorize$': ['.*'] # OAuth, never cached
Inventory the parameters your website reads on the server (controllers, Twig app.request.query, resolvers like the
smart content pagination) before switching: a parameter that is not kept never reaches the application. Parameters read
only by JavaScript (location.search) are unaffected, the URL in the browser is not changed.
Only GET and HEAD requests are filtered (in both modes): no other request is answered from the cache, so a form POST keeps all its query parameters.
Each subscriber can be switched off with enabled: false. The resolved cookie names are also
exposed as the container parameters alengo_http_cache.cta_interests.cookie_name and
alengo_http_cache.cta_referer.cookie_name for container-side consumers (e.g. a form
controller that reads the cookie).