[TYPO3-mvc] Strange caching behaviour
Helmut Hummel
helmut.hummel at typo3.org
Mon Apr 21 23:41:54 CEST 2014
Hi Jan!
On 20.04.14 12:38, Jan Kornblum wrote:
> Now calling (1) again after this, the page displays the plugins output
> of (3), the show action instead of the list action!? The result of (3)
> seems to have been cached for (1), because a cHash was missing when
> calling (3).
>
> Is this a bug?
It works as desinged at least.
TYPO3 caches a page on first hit.
If different parameters cause a different page output, then the version
of the page is cached which is rendered first.
Since there is the need to have different output for one page, different
cache entries are written for one page in the following conditions:
1) Different page type
2) Different usergroup combinations
3) Different matched TypoScript conditions
4) Different (valid) cHash value
So if you call the page first with parameters that do not cause any of
these conditions to be true, but renders different output than without
these parameters, then still the page will be cached and you get this
cached result even when skipping these parameters on consecutive calls.
> I'm aware that the caching mechanism can't work correctly when the
> cHash param is missing or incorrect but i'm sure that all the links are
> built correctly from inside my plugin (containing a cHash).
>
> The problem is, that this scenario regularly happens to a live website
> and i don't know how to prevent it (as everybody in the www might just
> call (3) without any cHash param).
Of course you can't control with which parameters your website is called
and indeed this behavior is not wanted.
> How can i prevent this behaviour?
The issue you have is that a URL is called which (in the sense of the
caching implementation) is not valid, as it misses the cHash which makes
the URL valid.
You have some control what should happen in such a case, but first, you
need to tell TYPO3 which parameters require a cHash to be calculated.
You can do so by adding all these parameters to:
TYPO3_CONF_VARS[FE][cHashRequiredParameters]
e.g.:
TYPO3_CONF_VARS[FE][cHashRequiredParameters] =
tx_news_pi1[news],tx_news_pi1[action],tx_news_pi1[controller]
When configuring that and URLs are called with these parameters set, but
no cHash parameter is set, then you can choose between two different
behaviors:
1) Throw a 404 - Page Not Found error
2) Disable the cache
You can control this with the following configuration:
TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']
I would recommend to let a 404 error occur in case the cHash is invalid
and at the same time use and configure realurl so that all query
parameters are transformed into a path. If you do so, realurl saves the
cHash for the URL in the database and correctly populates it if the URL
is requested.
Then you will have two different URLs similar to these:
/pluginpage.html
/my/show/model.html
Now it is impossible to call the second URL without cHash as realurl
will automatically populate it.
Given the recommendation above the following URL:
pluginpage.html?tx_ext[controller]=MyController&tx_ext[action]=show&tx_ext[myModel]=123
Would lead to a 404 so that search engines will quickly throw this out
of their index (asuming that search results are the main reason why such
URLs are called).
HTH
Kind regards,
Helmut
--
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 Core Developer, TYPO3 Security Team Member
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the TYPO3-project-typo3v4mvc
mailing list