Prevent 'type' parameter from being cached in links
guelzow opened this issue · 7 comments
Hi everyone.
When
- different page types are used
- 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:
- Clear the cache
- Open a shop page with a page type in the url
- All links are page typed as they should
- Revisit the same page, without a page type
- 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:
- Create a custom middleware to grab the ServerRequest
- Store it somewhere for later usage
- 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:
- Pass the page type to the cache proxy constructor (https://github.com/aimeos/aimeos-typo3/blob/master/Classes/Base/Context.php#L68-L98)
- Pass the page type then in
$conf
to the cache object (https://github.com/aimeos/ai-typo3/blob/master/lib/custom/src/MAdmin/Cache/Proxy/Typo3.php#L35-L57) - Use the page type in the cache prefix(https://github.com/aimeos/ai-typo3/blob/master/lib/custom/src/MW/Cache/Typo3.php#L37)
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.
Merged