|
13 | 13 |
|
14 | 14 | use Kitodo\Dlf\Pagination\PageGridPagination; |
15 | 15 | use Kitodo\Dlf\Pagination\PageGridPaginator; |
| 16 | +use TYPO3\CMS\Core\Cache\CacheManager; |
16 | 17 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
17 | 18 |
|
18 | 19 | /** |
@@ -43,19 +44,31 @@ public function mainAction(): void |
43 | 44 | return; |
44 | 45 | } |
45 | 46 |
|
46 | | - $entryArray = []; |
47 | | - |
48 | | - $numPages = $this->document->getCurrentDocument()->numPages; |
49 | | - // Iterate through visible page set and display thumbnails. |
50 | | - for ($i = 1; $i <= $numPages; $i++) { |
51 | | - $foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']); |
52 | | - $foundEntry['state'] = ($i == $this->requestData['page']) ? 'cur' : 'no'; |
53 | | - $entryArray[] = $foundEntry; |
54 | | - } |
55 | | - |
56 | 47 | // Get current page from request data because the parameter is shared between plugins |
57 | 48 | $currentPage = $this->requestData['page'] ?? 1; |
58 | 49 |
|
| 50 | + // access cachemanager for pagegrid |
| 51 | + $cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class); |
| 52 | + $cache = $cacheManager->getCache('tx_dlf_pagegrid'); |
| 53 | + $cacheKey = $this->document->getCurrentDocument()->recordId; |
| 54 | + $cachedData = $cache->get($cacheKey); |
| 55 | + |
| 56 | + if ($cachedData) { |
| 57 | + $entryArray = $cachedData; //load from cache |
| 58 | + } else { |
| 59 | + $numPages = $this->document->getCurrentDocument()->numPages; |
| 60 | + |
| 61 | + for ($i = 1; $i <= $numPages; $i++) { |
| 62 | + $foundEntry = $this->getEntry($i, $this->extConf['files']['fileGrpThumbs']); |
| 63 | + $foundEntry['state'] = 'no'; |
| 64 | + $entryArray[] = $foundEntry; |
| 65 | + } |
| 66 | + |
| 67 | + $cache->set($cacheKey, $entryArray, [], 86400); |
| 68 | + } |
| 69 | + // mark currently active page |
| 70 | + $entryArray[$currentPage - 1]['state'] = 'cur'; |
| 71 | + |
59 | 72 | $itemsPerPage = $this->settings['paginate']['itemsPerPage']; |
60 | 73 | if (empty($itemsPerPage)) { |
61 | 74 | $itemsPerPage = 25; |
|
0 commit comments