From 35eea83d9f1a89c440c271c6e64be7fd7990f12d Mon Sep 17 00:00:00 2001 From: Marcus Schwemer Date: Mon, 19 Mar 2018 16:48:44 +0100 Subject: [PATCH 1/4] [FEATURE] Trigger also processCmdmap_postProcess This function triggers the already registered hook "processCmdmap_postProcess" and clears the caches of the page and its children, if it is moved within the pagetree. --- Classes/Hook/DataHandlerDetector.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Classes/Hook/DataHandlerDetector.php b/Classes/Hook/DataHandlerDetector.php index a47b7d7..bfd6a99 100644 --- a/Classes/Hook/DataHandlerDetector.php +++ b/Classes/Hook/DataHandlerDetector.php @@ -58,7 +58,32 @@ public function __construct() */ public function processDatamap_afterDatabaseOperations($status, string $table, $id, array $changedFields, DataHandler $dataHandler) { - // @codingStandardsIgnoreEnd + $this->clearCachedPagesFoundByAgents($table, $id, $changedFields); + + } + + /** + * @param string $status The status of the record + * @param string $table Database table name + * @param int|string $id The uid of the record or something like "NEW59785a1ec52" if the record is new + * @param int $pageIdentifier The id of the page + * @throws \Exception + */ + public function processCmdmap_postProcess($status, $table, $id, $pageIdentifier) + { + $this->clearCachedPagesFoundByAgents($table, $id, ['uid' => $pageIdentifier]); + + } + + /** + * @param string $table + * @param $id + * @param array $changedFields of an array containing just the uid of a page + * @throws \Exception + */ + protected function clearCachedPagesFoundByAgents(string $table, $id, array $changedFields) + { +// @codingStandardsIgnoreEnd $expiredPages = []; if ($this->configuration->isConfigured($table)) { $agentConfigurations = $this->configuration->getAgentsForTable($table); From 5239b65f766148269cccdc827bbc6273c207c4eb Mon Sep 17 00:00:00 2001 From: Marcus Schwemer Date: Mon, 19 Mar 2018 17:07:11 +0100 Subject: [PATCH 2/4] [FEATURE] Add agent for moved pages If this agent is activated, the caches of all children of this page will be cleared, when it is moved via the page tree. --- Classes/Agents/PageMovedAgent.php | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Classes/Agents/PageMovedAgent.php diff --git a/Classes/Agents/PageMovedAgent.php b/Classes/Agents/PageMovedAgent.php new file mode 100644 index 0000000..5eba99d --- /dev/null +++ b/Classes/Agents/PageMovedAgent.php @@ -0,0 +1,36 @@ +pageMovedInTree($changedFields)) { + $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class); + $pages = $queryGenerator->getTreeList($uid, 99, 0, 1); + $pagesUidList = array_merge($pagesUidList, explode(',', $pages)); + } + } + + return $pagesUidList; + } + + /** + * Returns true, if the page was moved via the page tree + * + * @param array $changedFields + * @return bool + */ + protected function pageMovedInTree(array $changedFields): bool + { + return array_keys($changedFields) === ['uid']; + } +} From c5270795822123b405810c531de2a656a588c25d Mon Sep 17 00:00:00 2001 From: Marcus Schwemer Date: Tue, 20 Mar 2018 14:06:04 +0100 Subject: [PATCH 3/4] [BUGFIX] Use correct namespace for PageMovedAgent This agent was developed in a project, but is moved to EXT:cache_automation. --- Classes/Agents/PageMovedAgent.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Classes/Agents/PageMovedAgent.php b/Classes/Agents/PageMovedAgent.php index 5eba99d..a4c44b9 100644 --- a/Classes/Agents/PageMovedAgent.php +++ b/Classes/Agents/PageMovedAgent.php @@ -1,11 +1,9 @@ Date: Wed, 27 Jun 2018 10:15:46 +0200 Subject: [PATCH 4/4] [FEATURE] Split array of expired pages into chunks On high load systems this call might run into database limitations, if the page cache of is cleared, when very many pages have to be cleared. https://projekte.in2code.de/issues/31515 --- Classes/Hook/DataHandlerDetector.php | 8 +++++++- ext_conf_template.txt | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 ext_conf_template.txt diff --git a/Classes/Hook/DataHandlerDetector.php b/Classes/Hook/DataHandlerDetector.php index bfd6a99..13aa7aa 100644 --- a/Classes/Hook/DataHandlerDetector.php +++ b/Classes/Hook/DataHandlerDetector.php @@ -99,7 +99,13 @@ protected function clearCachedPagesFoundByAgents(string $table, $id, array $chan } if (count($expiredPages) !== 0) { - $this->cacheService->clearPageCache(array_unique($expiredPages)); + $expiredPages = array_unique($expiredPages); + // TODO: use new API in TYPO3 V9 + $extensionConfiguration = $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cache_automation']); + $arrayChunks = array_chunk($expiredPages, $extensionConfiguration['numberOfCachedPagesToClear']); + foreach ($arrayChunks as $singleChunk) { + $this->cacheService->clearPageCache($singleChunk); + } } } } diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..d34c889 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,2 @@ +# cat=basic/enable; type=string; label=Number of cached pages that will be cleared in one chunk +numberOfCachedPagesToClear = \ No newline at end of file