首页 > 解决方案 > 如何为自定义内容元素定义自定义缓存生命周期?

问题描述

TypoScript 不应该cache适用于这样的自定义内容元素:

tt_content {
    my_custom_element =< lib.contentElement
    my_custom_element {
        // tested also with stdWrap.cache
        cache {
            key = my_custom_element
            // 10 seconds to test
            lifetime = 10
        }
        templateName = MyCustomElement
        dataProcessing.10 = Example\Project\DataProcessing\FetchDataProcessor
        dataProcessing.10 {
            fetchUri = https://www.example.com/resource
            as = fetched_data
        }
    }
}

...还是我解释错了?
https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Cache.html
我希望为此内容元素定义一个自定义缓存生命周期。

标签: typo3typoscript

解决方案


可能的解决方案:

tt_content {
    // COA_INT to ensure the block .my_custom_element isn't cached
    my_custom_element = COA_INT
    my_custom_element {
        10 =< lib.contentElement
        10 {
            // Re-add cache for the block .10
            cache {
                // Use UID of content element when user can edit content of it
                key = my_custom_element_{field:uid}
                key.insertData = 1
                // For test currently 10 seconds
                lifetime = 10
            }
            templateName = MyCustomElement
            dataProcessing.10 = Example\Project\DataProcessing\FetchDataProcessor
            dataProcessing.10 {
                fetchUri = https://www.example.com/resource
                as = fetched_data
            }
        }
    }
}

但它有(巨大的)缺点:

  • 放置内容元素的页面 HTML 不会被浏览器缓存。
  • 静态文件缓存扩展也不适用于此页面。

推荐阅读