Skip to content

Commit

Permalink
[FEATURE] Add caching to pagegrid (#1406)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kubina <[email protected]>
Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2025
1 parent 3e76e97 commit fca97b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Classes/Controller/PageGridController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Kitodo\Dlf\Pagination\PageGridPagination;
use Kitodo\Dlf\Pagination\PageGridPaginator;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -44,14 +45,24 @@ public function mainAction(): ResponseInterface
return $this->htmlResponse();
}

// Access cachemanager for pagegrid
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('tx_dlf_pagegrid');
$cacheKey = $this->document->getCurrentDocument()->recordId;
$cachedData = $cache->get($cacheKey);

$entryArray = [];

$numPages = $this->document->getCurrentDocument()->numPages;
// Iterate through visible page set and display thumbnails.
for ($i = 1; $i <= $numPages; $i++) {
$foundEntry = $this->getEntry($i);
$foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no';
$entryArray[] = $foundEntry;
if ($cachedData) {
$entryArray = $cachedData; // Load from cache
} else {
$numPages = $this->document->getCurrentDocument()->numPages;
// Iterate through visible page set and display thumbnails.
for ($i = 1; $i <= $numPages; $i++) {
$foundEntry = $this->getEntry($i);
$foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no';
$entryArray[] = $foundEntry;
}
$cache->set($cacheKey, $entryArray);
}

// Get current page from request data because the parameter is shared between plugins
Expand Down
9 changes: 9 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_doc']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day
}
// Use Caching Framework for PageGrid $entryArray caching
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid'] ??= [];

if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['backend'] = 'TYPO3\\CMS\\Core\\Cache\\Backend\\FileBackend';
}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['options']['defaultLifeTime'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_dlf_pagegrid']['options']['defaultLifeTime'] = 86400; // 86400 seconds = 1 day
}
// Add new renderType for TCA fields.
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][] = [
'nodeName' => 'editInProductionWarning',
Expand Down

0 comments on commit fca97b7

Please sign in to comment.