Search by

alengo / sulu-http-cache-bundle

alengodev

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

Statistics

Installs: 54

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.0 2026-12-02 21:00 UTC

This package is auto-updated.

Last update: 2026-12-02 21:01:22 UTC


README

HTTP-cache helpers for Sulu / Symfony, wired onto the FOS EventDispatchingHttpCache (reverse-proxy) kernel:

  • StripQueryParametersSubscriber — removes tracking query parameters (utm_*, gclid, fbclid, …) at PRE_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).