How do I get Magento to serve up the cached version of the page when I have unique URL parameters?

StackOverflow https://stackoverflow.com/questions/15410713

Pregunta

It's a simple question with no answer in search(google/bing/stackoverflow). The answer of course could be complicated.

I've read a couple articles on FPC within Magento, and have yet to really nail down where I need to add or create code so that when certain URL parameters are sent it serves up cached version of the page and not try and re-cache with the URL parameters.

http://www.kingletas.com/2012/09/how-does-magento-full-page-cache-works.html

So for example, when you go to http://www.example.com/shoes it loads the correct cached version. however, with google analytics and any other type of 3rd party reporting, especially with unique identifiers, it will reload the page as if it wasn't cached. So http://www.example.com/shoes?utm_key=A1537BD94EF07 would create a new cached version of that page and so on.

I would like to be able to exclude certain URL parameters and not all. Mainly any parameter I am using for tracking of customers.

As far as code, I have not come up with anything, due to the fact of the complexity of FPC and not having a dev site currently setup to test on.

Any leads as to where I can add this exception would be helpful, thanks!

EDIT: I would like to add that I am working with the Enterprise Edition. And using the Redis for cache.

¿Fue útil?

Solución

I developed my own extension on the fix.

In short the get parameters are used in the cache ID. So in order to bypass this, I created an extension that changed the following:

/app/code/core/Enterprise/PageCache/Model/Processor/Category.php

Two functions where changed

protected function _getQueryParams()

AND

public function getPageIdWithoutApp(Enterprise_PageCache_Model_Processor $processor)

/app/code/core/Enterprise/PageCache/Model/Processor/Default.php

One function was changed

public function getPageIdWithoutApp(Enterprise_PageCache_Model_Processor $processor)

Once changed, it no longer created the cache ID with my specified tracking parameters.

example:

public function getPageIdWithoutApp(Enterprise_PageCache_Model_Processor $processor)
{
    $queryParams = $_GET;
    ksort($queryParams);
    /**
    * unset known tracking codes
    */
    unset($queryParams["trk_msg"]);
    unset($queryParams["trk_contact"]);
    unset($queryParams["utm_source"]);
    unset($queryParams["utm_medium"]);
    unset($queryParams["utm_term"]);
    unset($queryParams["utm_campaign"]);
    unset($queryParams["utm_content"]);
    /** End Edit */
    $queryParamsHash = md5(serialize($queryParams));
    return $processor->getRequestId() . '_' . $queryParamsHash;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top