mhirdes
mhirdes

Reputation: 303

User specific content in TYPO3 and caching

How to show not cached fe_user data in TYPO3? According to Prevent to Cache Login Information. The ViewHelper sets $GLOBALS['TSFE']->no_cache = 1 if the user logged in. Is there a better way? Because not the whole page should not be cached, only some parts of it.

Upvotes: 0

Views: 937

Answers (2)

Bernd Wilke πφ
Bernd Wilke πφ

Reputation: 10791

your example code disabled cache for the complete page. but you only need to disable cache for the part where you display the user specific data. As you can except any part from caching you need to select whether to cache only

  • one content element (especially for plugins this is standard behaviour: just declare your plugin as uncachable in your ext_localconf.php)
  • one column (make sure you use a COA_INT (or other uncached object) in your typoscript)
  • one viewhelper (make your viewhelper uncachable [1] or use the v:render.uncache() VH from EXT:vhs)

[1] as a viewhelper is derived from AbstractConditionViewHelper, which uses the Compilable Interface, which caches the result, the compile() method from AbstractConditionViewHelper must be rewritten and return the constant

\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION

like this:

public function compile(
    $argumentsVariableName,
    $renderChildrenClosureVariableName,
    &$initializationPhpCode,
    \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode,
    \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
) {
    parent::compile(
        $argumentsVariableName,
        $renderChildrenClosureVariableName,
        $initializationPhpCode,
        $syntaxTreeNode,
        $templateCompiler
    );

    return \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION;
}

Upvotes: 1

Mario Naether
Mario Naether

Reputation: 1162

Unfortunately this is not possible.

The best way is, you render the not cached fe_user data with a AJAX called eID or TypeNum and the whole page is completly cached. like this one: http://www.typo3-tutorials.org/cms/typo3-und-ajax-wie-geht-das.html

Upvotes: 1

Related Questions