【问题标题】:User specific content in TYPO3 and cachingTYPO3 中的用户特定内容和缓存
【发布时间】:2017-11-17 15:00:47
【问题描述】:

如何在 TYPO3 中显示未缓存的 fe_user 数据?根据Prevent to Cache Login Information。 如果用户登录,ViewHelper 设置 $GLOBALS['TSFE']->no_cache = 1。有没有更好的方法?因为不是整个页面不应该被缓存,只有部分页面。

【问题讨论】:

    标签: caching typo3


    【解决方案1】:

    很遗憾,这是不可能的。

    最好的方法是,您使用称为 eID 或 TypeNum 的 AJAX 呈现未缓存的 fe_user 数据,并且整个页面被完全缓存。 像这个: http://www.typo3-tutorials.org/cms/typo3-und-ajax-wie-geht-das.html

    【讨论】:

    • 我想知道,为什么它比 COA_INT 更好?页面的其余部分仍然被缓存,并且在 AJAX 和 COA_INT 中都需要 TYPO3 的第二次性能。
    【解决方案2】:

    您的示例代码禁用了整个页面的缓存。但您只需要为显示用户特定数据的部分禁用缓存。除了缓存中的任何部分,您可以选择是否仅缓存

    • 一个内容元素(特别是对于插件,这是标准行为:只需在 ext_localconf.php 中将您的插件声明为不可缓存)
    • 一列(确保在您的打字稿中使用COA_INT(或其他未缓存的对象))
    • 一个 viewhelper(使您的 viewhelper 无法缓存 [1] 或使用来自 EXT:vhs 的 v:render.uncache() VH)

    [1] 由于 viewhelper 是从 AbstractConditionViewHelper 派生的,它使用 Compilable 接口,缓存结果,所以必须重写 AbstractConditionViewHelper 的 compile() 方法并返回常量

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

    像这样:

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 2018-03-06
      相关资源
      最近更新 更多