aimeos/aimeos-typo3

Prevent 'type' parameter from being cached in links

guelzow opened this issue · 7 comments

Hi everyone.

When

  1. different page types are used
  2. the Aimeos TYPO3 cache is used

The links from the Aimeos TYPO3 cache contain the page type parameters from the fist call that ends up being cached.

How to reproduce:

  1. Clear the cache
  2. Open a shop page with a page type in the url
  3. All links are page typed as they should
  4. Revisit the same page, without a page type
  5. All links are still page typed

Our workaround so far:
Set the Aimeos cache to None.

Proposed solution:
None so far, but we do have an idea or two.

Tobi

Proposed solution:
The currently used page type is located in the ServerRequest object.
It's available in the

$GLOBALS['TYPO3_REQUEST']->getAttribute( 'routing' )->getPageType()

To get it by the book would require the usage of a custom middleware, which stores it somewhere we can access it more safely.

And to get rid of the caching collusions with the page type, we need to add the page type to the caching prefix here:
https://github.com/aimeos/ai-typo3/blob/2020.10.6/lib/custom/src/MAdmin/Cache/Proxy/Typo3.php#L47

if (!isset($this->object)) {
    $preFix = $this->context->getConfig()->get('madmin/cache/prefix');
    $siteId = $this->context->getLocale()->getSiteItem()->getId();
    $pageType = $this->retrievePageType();
    $conf = [
        'siteid' => $preFix . $siteId . $pageType
    ];

    $this->object = CacheFactory::create('Typo3', $conf, $this->cache);
}

return $this->object;

To wrap it up:

  1. Create a custom middleware to grab the ServerRequest
  2. Store it somewhere for later usage
  3. Add it to the caching prefix.

Thanks to Oliver Bartsch for pointing me into the right direction with the ServerRequest.

Tobi

What is your use case for different page types? Can you give us a praktical example when the problem occurs in your case?

We have two different layouts for the shop.
One is rendered in a browser, the other one is rendered in an app.

The best way could be:

The first step isn't yet perfect because you have to access the page type from a global external source.

The first step isn't yet perfect because you have to access the page type from a global external source.

Absolutely.
The most by-the-book way would be to get it with a custom middleware and then store it somewhere we can access is easily.

Hi everyone.

See:
#173
aimeos/ai-typo3#29

Tobi

Merged