‪TYPO3CMS  ‪main
TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator Class Reference

Public Member Functions

 __construct (protected readonly FrontendInterface $runtimeCache, protected readonly EventDispatcherInterface $eventDispatcher, protected readonly ConnectionPool $connectionPool)
 
 calculateLifetimeForPage (int $pageId, array $pageRecord, array $renderingInstructions, int $defaultCacheTimoutInSeconds, Context $context)
 

Protected Member Functions

int calculatePageCacheLifetime (array $tablesToConsider, int $currentTimestamp)
 
array getCurrentPageCacheConfiguration (int $currentPageId, array $renderingInstructions)
 
int getFirstTimeValueForRecord (string $tableDef, int $currentTimestamp)
 

Protected Attributes

int $defaultCacheTimeout = 86400
 

Detailed Description

Calculates the max lifetime the given page should be stored in TYPO3's page cache.

The "lifetime" is the number of seconds from the current time, it is not a full time/timestamp Example: If the lifetime is "3600" (=1h), the page will be cached for 1h.

This class is not part of the TYPO3 Core API

Definition at line 38 of file CacheLifetimeCalculator.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::__construct ( protected readonly FrontendInterface  $runtimeCache,
protected readonly EventDispatcherInterface  $eventDispatcher,
protected readonly ConnectionPool  $connectionPool 
)

Definition at line 42 of file CacheLifetimeCalculator.php.

Member Function Documentation

◆ calculateLifetimeForPage()

TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::calculateLifetimeForPage ( int  $pageId,
array  $pageRecord,
array  $renderingInstructions,
int  $defaultCacheTimoutInSeconds,
Context  $context 
)

◆ calculatePageCacheLifetime()

int TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::calculatePageCacheLifetime ( array  $tablesToConsider,
int  $currentTimestamp 
)
protected

Calculates page cache timeout according to the records with starttime/endtime on the page.

Returns
‪int Page cache timeout or PHP_INT_MAX if the timeout cannot be determined

Definition at line 110 of file CacheLifetimeCalculator.php.

References TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator\getFirstTimeValueForRecord().

Referenced by TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator\calculateLifetimeForPage().

◆ getCurrentPageCacheConfiguration()

array TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::getCurrentPageCacheConfiguration ( int  $currentPageId,
array  $renderingInstructions 
)
protected

Obtains a list of table/pid pairs to consider for page caching.

TS configuration looks like this:

The cache lifetime of all pages takes starttime and endtime of news records of page 14 into account: config.cache.all = tt_news:14

The cache lifetime of the current page allows to take records (e.g. fe_users) into account: config.cache.all = fe_users:current

The cache lifetime of page 42 takes starttime and endtime of news records of page 15 and addresses of page 16 into account: config.cache.42 = tt_news:15,tt_address:16

Returns
‪array Array of 'tablename:pid' pairs. There is at least a current page id in the array
See also
calculatePageCacheLifetime()

Definition at line 138 of file CacheLifetimeCalculator.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator\calculateLifetimeForPage().

◆ getFirstTimeValueForRecord()

int TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::getFirstTimeValueForRecord ( string  $tableDef,
int  $currentTimestamp 
)
protected

Find the minimum starttime or endtime value in the table and pid that is greater than the current time.

Parameters
string$tableDef‪Table definition (format tablename:pid)
int$currentTimestamp‪the UNIX timestamp of the current time
Exceptions

Definition at line 159 of file CacheLifetimeCalculator.php.

References if, TYPO3\CMS\Core\Database\Connection\PARAM_INT, and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator\calculatePageCacheLifetime().

Member Data Documentation

◆ $defaultCacheTimeout

int TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator::$defaultCacheTimeout = 86400
protected

Definition at line 40 of file CacheLifetimeCalculator.php.