| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace Opentalent\OtTemplating\Utility;
- use Psr\Http\Message\ResponseInterface;
- use RuntimeException;
- use TYPO3\CMS\Core\DataHandling\DataHandler;
- use TYPO3\CMS\Core\Service\OpcodeCacheService;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Install\Service\ClearCacheService;
- use TYPO3\CMS\Install\Service\Typo3tempFileService;
- class CacheManager
- {
- /**
- * Clears the page cache
- *
- * @param int $pageUid
- */
- public static function clearPageCache(int $pageUid) {
- $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
- $dataHandler->start([], []);
- $dataHandler->clear_cacheCmd($pageUid);
- }
- /**
- * Clears cache for each page of the site
- *
- * @param int $pageUid
- */
- public static function clearSiteCache(int $pageUid) {
- $pageRepository = new \Opentalent\OtTemplating\Page\OtPageRepository();
- $rootPage = $pageRepository->getRootPageFor($pageUid);
- $pages = $pageRepository->getAllSubpagesForPage($rootPage['uid']);
- $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
- $dataHandler->start([], []);
- foreach ($pages as $page) {
- $dataHandler->clear_cacheCmd($page['uid']);
- }
- }
- /**
- * Clear cache framework and opcode caches
- * (@see TYPO3\CMS\Install\Controller\MaintenanceController )
- */
- public static function clearAllCache(): ResponseInterface
- {
- GeneralUtility::makeInstance(ClearCacheService::class)->clearAll();
- GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
- }
- /**
- * Clear typo3temp/assets
- * (@see TYPO3\CMS\Install\Controller\MaintenanceController )
- */
- public static function clearAssetsTempfiles()
- {
- $typo3tempFileService = new Typo3tempFileService();
- try {
- $typo3tempFileService->clearAssetsFolder("/typo3temp/assets/css");
- } catch (RuntimeException $e) {
- // 1501781454 code means directory does not exist, we can ignore this error
- if ($e->getCode() != 1501781454) {
- throw $e;
- }
- }
- try {
- $typo3tempFileService->clearAssetsFolder("/typo3temp/assets/js");
- } catch (RuntimeException $e) {
- // 1501781454 code means directory does not exist, we can ignore this error
- if ($e->getCode() != 1501781454) {
- throw $e;
- }
- }
- }
- }
|