forked from TYPO3-Documentation/TYPO3CMS-Reference-CoreApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] #102422 - Introduce CacheDataCollector API
Resolves: TYPO3-Documentation/Changelog-To-Doc#1042 Releases: main, 13.4
- Loading branch information
1 parent
32bcfa3
commit d1f39fe
Showing
7 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...ation/ApiOverview/RequestLifeCycle/RequestAttributes/FrontendCacheCollector.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
.. include:: /Includes.rst.txt | ||
|
||
.. index:: | ||
Request attribute; Frontend cache collector | ||
.. _typo3-request-attribute-frontend-cache-collector: | ||
|
||
======================== | ||
Frontend cache collector | ||
======================== | ||
|
||
.. versionadded:: 13.3 | ||
This request attribute is a replacement for | ||
:php:`TypoScriptFrontendController->addCacheTags()` and | ||
:php:`TypoScriptFrontendController->getPageCacheTags()` which has been | ||
deprecated with TYPO3 v13.3. | ||
|
||
An API is available to collect cache tags and their corresponding lifetime. This | ||
API is used in TYPO3 to accumulate cache tags from page cache and content object | ||
cache. | ||
|
||
The API is implemented as a PSR-7 request attribute `frontend.cache.collector`. | ||
|
||
Every cache tag has a lifetime. The minimum lifetime is calculated | ||
from all given cache tags. API users do not have to deal with it individually. | ||
The default lifetime for a cache tag is 86400 seconds (24 hours). | ||
|
||
|
||
.. _typo3-request-attribute-frontend-cache-collector-example-add-single-cache-tag: | ||
|
||
Example: Add a single cache tag | ||
=============================== | ||
|
||
.. code-block:: php | ||
// use TYPO3\CMS\Core\Cache\CacheTag; | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->addCacheTags( | ||
new CacheTag('tx_myextension_mytable'), | ||
); | ||
.. _typo3-request-attribute-frontend-cache-collector-example-add-multiple-cache-tags: | ||
|
||
Example: Add multiple cache tags with different lifetimes | ||
========================================================= | ||
|
||
.. code-block:: php | ||
// use TYPO3\CMS\Core\Cache\CacheTag; | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->addCacheTags( | ||
new CacheTag('tx_myextension_mytable_123', 3600), | ||
new CacheTag('tx_myextension_mytable_456', 2592000), | ||
); | ||
.. _typo3-request-attribute-frontend-cache-collector-example-remove-single-cache-tag: | ||
|
||
Example: Remove a single cache tag | ||
================================== | ||
|
||
.. code-block:: php | ||
// use TYPO3\CMS\Core\Cache\CacheTag; | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->removeCacheTags( | ||
new CacheTag('tx_myextension_mytable_123'), | ||
); | ||
.. _typo3-request-attribute-frontend-cache-collector-example-remove-multiple-cache-tags: | ||
|
||
Example: Remove multiple cache tags | ||
=================================== | ||
|
||
.. code-block:: php | ||
// use TYPO3\CMS\Core\Cache\CacheTag; | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->removeCacheTags( | ||
new CacheTag('tx_myextension_mytable_123'), | ||
new CacheTag('tx_myextension_mytable_456'), | ||
); | ||
.. _typo3-request-attribute-frontend-cache-collector-example-get-minimum-lifetime: | ||
|
||
Example: Get minimum lifetime, calculated from all cache tags | ||
============================================================= | ||
|
||
.. code-block:: php | ||
:caption: Get minimum lifetime, calculated from all cache tags | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->getLifetime(); | ||
.. _typo3-request-attribute-frontend-cache-collector-example-get-all-cache-tags: | ||
|
||
Example: Get all cache tags | ||
=========================== | ||
|
||
.. code-block:: php | ||
$cacheDataCollector = $request->getAttribute('frontend.cache.collector'); | ||
$cacheDataCollector->getCacheTags(); | ||
.. _typo3-request-attribute-frontend-cache-collector-api: | ||
|
||
API | ||
=== | ||
|
||
.. include:: /CodeSnippets/Manual/Cache/CacheDataCollector.rst.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
return [ | ||
[ | ||
'action' => 'createPhpClassDocs', | ||
'class' => \TYPO3\CMS\Core\Cache\CacheDataCollector::class, | ||
'targetFileName' => 'CodeSnippets/Manual/Cache/CacheDataCollector.rst.txt', | ||
'withCode' => false, | ||
], | ||
]; |
29 changes: 29 additions & 0 deletions
29
Documentation/CodeSnippets/Manual/Cache/CacheDataCollector.rst.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
.. php:namespace:: TYPO3\CMS\Core\Cache | ||
.. php:class:: CacheDataCollector | ||
.. php:method:: getCacheTags() | ||
:returns: `\CacheTag[]` | ||
|
||
.. php:method:: addCacheTags(\TYPO3\CMS\Core\Cache\CacheTag ...$cacheTags) | ||
:param $cacheTags: the cacheTags | ||
|
||
.. php:method:: removeCacheTags(\TYPO3\CMS\Core\Cache\CacheTag ...$cacheTags) | ||
:param $cacheTags: the cacheTags | ||
|
||
.. php:method:: restrictMaximumLifetime(int $lifetime) | ||
:param $lifetime: the lifetime | ||
|
||
.. php:method:: resolveLifetime() | ||
:returns: `int` | ||
|
||
.. php:method:: enqueueCacheEntry(\TYPO3\CMS\Core\Cache\CacheEntry $deferredCacheItem) | ||
:param $deferredCacheItem: the deferredCacheItem | ||
|
||
.. php:method:: getCacheEntries() | ||
:returns: `\CacheEntry[]` |