CacheLifetimeCalculator
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
Attributes
- #[Autoconfigure]
- $public: true
Table of Contents
Constants
- defaultCacheTimeout = 86400
Properties
- $connectionPool : ConnectionPool
- $eventDispatcher : EventDispatcherInterface
- $runtimeCache : FrontendInterface
Methods
- __construct() : mixed
- calculateLifetimeForPage() : int
- Get the cache lifetime in seconds for the given page.
- calculateLifetimeForRow() : int
- Get the cache lifetime in seconds for the given record.
- calculatePageCacheLifetime() : int
- Calculates page cache timeout according to the records with starttime/endtime on the page.
- getCurrentPageCacheConfiguration() : array<string|int, mixed>
- Obtains a list of table/pid pairs to consider for page caching.
- getFirstTimeValueForRecord() : int
- Find the minimum starttime or endtime value in the table and pid that is greater than the current time.
Constants
defaultCacheTimeout
protected
mixed
defaultCacheTimeout
= 86400
Properties
$connectionPool read-only
protected
ConnectionPool
$connectionPool
$eventDispatcher read-only
protected
EventDispatcherInterface
$eventDispatcher
$runtimeCache read-only
protected
FrontendInterface
$runtimeCache
Attributes
- #[Autowire]
- $service: 'cache.runtime'
Methods
__construct()
public
__construct(FrontendInterface $runtimeCache, EventDispatcherInterface $eventDispatcher, ConnectionPool $connectionPool) : mixed
Parameters
- $runtimeCache : FrontendInterface
- $eventDispatcher : EventDispatcherInterface
- $connectionPool : ConnectionPool
calculateLifetimeForPage()
Get the cache lifetime in seconds for the given page.
public
calculateLifetimeForPage(int $pageId, array<string|int, mixed> $pageRecord, array<string|int, mixed> $renderingInstructions, int $defaultCacheTimoutInSeconds, Context $context) : int
Parameters
- $pageId : int
- $pageRecord : array<string|int, mixed>
- $renderingInstructions : array<string|int, mixed>
- $defaultCacheTimoutInSeconds : int
- $context : Context
Return values
intcalculateLifetimeForRow()
Get the cache lifetime in seconds for the given record.
public
calculateLifetimeForRow(string $tableName, array<string|int, mixed> $record[, int $defaultCacheTimoutInSeconds = 0 ]) : int
Parameters
- $tableName : string
- $record : array<string|int, mixed>
- $defaultCacheTimoutInSeconds : int = 0
Return values
intcalculatePageCacheLifetime()
Calculates page cache timeout according to the records with starttime/endtime on the page.
protected
calculatePageCacheLifetime(array<string|int, mixed> $tablesToConsider, int $currentTimestamp) : int
Parameters
- $tablesToConsider : array<string|int, mixed>
- $currentTimestamp : int
Return values
int —Page cache timeout or PHP_INT_MAX if the timeout cannot be determined
getCurrentPageCacheConfiguration()
Obtains a list of table/pid pairs to consider for page caching.
protected
getCurrentPageCacheConfiguration(int $currentPageId, array<string|int, mixed> $renderingInstructions) : array<string|int, mixed>
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
Parameters
- $currentPageId : int
- $renderingInstructions : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Array of 'tablename:pid' pairs. There is at least a current page id in the array
getFirstTimeValueForRecord()
Find the minimum starttime or endtime value in the table and pid that is greater than the current time.
protected
getFirstTimeValueForRecord(string $tableDef, int $currentTimestamp) : int
Parameters
- $tableDef : string
-
Table definition (format tablename:pid)
- $currentTimestamp : int
-
the UNIX timestamp of the current time
Tags
Return values
int —Value of the next start/stop time or PHP_INT_MAX if not found