We want to display customer (actually customer-group) specific information on product detail pages in Shopware 6.

There seems to be the HTTP cache and we are afraid that the page would be cached if a specific customer group displays the page and the information would be leaked to non-customers.

Is this assumption correct?

[The documentation](https://github.com/shopware/platform/blob/d8e8619db9d08ea9bd7689cdac28fce295d652b6/src/Storefront/Framework/Cache/CacheResponseSubscriber.php#L111) does not reveal much information about this.

Is there a way to set specific cache tags, so that the information is only displayed to the correct customer group?

Or do we need to fetch the data dynamically via AJAX?

Bonus question: Can the HTTP cache be simulated in automatic tests to ensure the functionality works?

What I found out so far:

* The is annotation `@httpCache` for controller, which seems to control whether a page is cached or not
* The cache key is generated in `\Shopware\Storefront\Framework\Cache\HttpCacheKeyGenerator::generate`. It take the full request URI into account, and some `cacheHash` which is injected. I believe it would not take the customer group into account
* Maybe this `generate()` method could be decorated, but I am not sure if that is the right way.
* There is a cookie being set `sw-cache-hash` which influences the caching. It takes the customer into account.
* `sw-cache-hash` is created [here](https://github.com/shopware/platform/blob/d8e8619db9d08ea9bd7689cdac28fce295d652b6/src/Storefront/Framework/Cache/CacheResponseSubscriber.php#L111):

```
  if ($context->getCustomer() || $cart->getLineItems()->count() > 0) {
      $cookie = Cookie::create(self::CONTEXT_CACHE_COOKIE, $this->buildCacheHash($context));
      $cookie->setSecureDefault($request->isSecure());

      $response->headers->setCookie($cookie);
  } else {
      $response->headers->removeCookie(self::CONTEXT_CACHE_COOKIE);
      $response->headers->clearCookie(self::CONTEXT_CACHE_COOKIE);
  }

```

So as soon you are logged in **or** have some items in the cart, a different cache hash is used. This depends on the following, but not on the customer group it self:

```
private function buildCacheHash(SalesChannelContext $context): string
{
    return md5(json_encode([
        $context->getRuleIds(),
        $context->getContext()->getVersionId(),
        $context->getCurrency()->getId(),
    ]));
}

```