|
15 | 15 | namespace AUS\AusDriverAmazonS3\Index; |
16 | 16 |
|
17 | 17 | use AUS\AusDriverAmazonS3\Driver\AmazonS3Driver; |
| 18 | +use TYPO3\CMS\Core\Cache\CacheManager; |
| 19 | +use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException; |
| 20 | +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; |
18 | 21 | use TYPO3\CMS\Core\Resource\File; |
19 | 22 | use TYPO3\CMS\Core\Resource\FileInterface; |
20 | 23 | use TYPO3\CMS\Core\Resource\Index\ExtractorInterface; |
|
30 | 33 | */ |
31 | 34 | class Extractor implements ExtractorInterface |
32 | 35 | { |
| 36 | + private ?FrontendInterface $cache = null; |
| 37 | + |
| 38 | + public function __construct() |
| 39 | + { |
| 40 | + try { |
| 41 | + $this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime'); |
| 42 | + } catch (NoSuchCacheException) { |
| 43 | + } |
| 44 | + } |
| 45 | + |
33 | 46 | /** |
34 | 47 | * Returns an array of supported file types; |
35 | 48 | * An empty array indicates all filetypes |
@@ -122,11 +135,23 @@ public function extractMetaData(File $file, array $previousExtractedData = []) |
122 | 135 | */ |
123 | 136 | public function getImageDimensionsOfRemoteFile(FileInterface $file): array |
124 | 137 | { |
| 138 | + $identifier = 'andersundsehr_aus_driver_amazon_s3_' . sha1($file->getIdentifier()); |
| 139 | + if ($this->cache?->has($identifier)) { |
| 140 | + $sizes = $this->cache->get($identifier); |
| 141 | + if (is_array($sizes) && count($sizes) === 2) { |
| 142 | + return $sizes; |
| 143 | + } |
| 144 | + } |
| 145 | + |
125 | 146 | $fileNameAndPath = $file->getForLocalProcessing(false); |
126 | 147 | $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $fileNameAndPath); |
127 | | - return [ |
| 148 | + $sizes = [ |
128 | 149 | $imageInfo->getWidth(), |
129 | 150 | $imageInfo->getHeight(), |
130 | 151 | ]; |
| 152 | + |
| 153 | + $this->cache?->set($identifier, $sizes); |
| 154 | + GeneralUtility::unlink_tempfile($fileNameAndPath); |
| 155 | + return $sizes; |
131 | 156 | } |
132 | 157 | } |
0 commit comments