浏览代码

fix the cache management

Olivier Massot 5 年之前
父节点
当前提交
4a14410443

+ 2 - 3
ot_templating/Classes/Controller/OtCustomizerController.php

@@ -3,7 +3,7 @@
 namespace Opentalent\OtTemplating\Controller;
 
 use Opentalent\OtTemplating\Page\OtPageRepository;
-use Opentalent\OtTemplating\Utility\CacheManager;
+use Opentalent\OtTemplating\Utility\OtCacheManager;
 use PDO;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
@@ -68,8 +68,7 @@ class OtCustomizerController extends ActionController {
         ;
 
         // Clear the site's cache
-        CacheManager::clearSiteCache($rootPageUid);
-//        CacheManager::clearAssetsTempfiles();
+        OtCacheManager::clearSiteCache($rootPageUid);
 
         $this->forward('index');
     }

+ 15 - 12
ot_templating/Classes/Utility/CacheManager.php → ot_templating/Classes/Utility/OtCacheManager.php

@@ -2,15 +2,16 @@
 
 namespace Opentalent\OtTemplating\Utility;
 
+use Opentalent\OtTemplating\Page\OtPageRepository;
 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;
+use TYPO3\CMS\Core\Cache\CacheManager;
 
-class CacheManager
+class OtCacheManager
 {
 
     /**
@@ -19,9 +20,11 @@ class CacheManager
      * @param int $pageUid
      */
     public static function clearPageCache(int $pageUid) {
-        $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
-        $dataHandler->start([], []);
-        $dataHandler->clear_cacheCmd($pageUid);
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
+        $cacheManager->flushCachesInGroupByTag(
+            'pages',
+            'pageId_' . $pageUid
+        );
     }
 
     /**
@@ -31,17 +34,17 @@ class CacheManager
      */
     public static function clearSiteCache(int $pageUid) {
 
-        $pageRepository = new \Opentalent\OtTemplating\Page\OtPageRepository();
+        $pageRepository = new OtPageRepository();
         $rootPage = $pageRepository->getRootPageFor($pageUid);
         $pages = $pageRepository->getAllSubpagesForPage($rootPage['uid']);
+        $pages[] = $rootPage;
 
-        $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
-        $dataHandler->start([], []);
-
-        foreach ($pages as $page) {
-            $dataHandler->clear_cacheCmd($page['uid']);
-        }
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
 
+        $tags = array_map(function ($page) {
+            return 'pageId_' . $page['uid'];
+        }, $pages);
+        $cacheManager->flushCachesInGroupByTags('pages', $tags);
     }
 
     /**

+ 1 - 2
ot_templating/Configuration/TypoScript/setup.txt

@@ -4,7 +4,7 @@
 [applicationContext == Development*]
     config.debug = 1
     config.contentObjectExceptionHandler = 0
-    config.no_cache = 1
+    #config.no_cache = 1
     config.admPanel = 0
 
     plugin.tx_vhs.settings.debug = 0
@@ -23,7 +23,6 @@ config.locale_all = fr_FR.utf-8
 config.concatenateCss = 1
 config.compressCss = 1
 config.compressJs = 1
-config.no_cache = 1
 
 # Important: if the filenames are not hashed, it ends up breaking the filename's length limit!
 plugin.tx_vhs.assets.mergedAssetsUseHashedFilename = 1

+ 8 - 0
ot_templating/Resources/Private/Layouts/Classic/Structures.html

@@ -27,6 +27,14 @@
                                        placeholder="Où?"
                                        value="{ot:request.getArgument(argument: 'search-loc')}"/>
 
+                                <f:comment><!--
+                                Important: if the cache is not disabled,
+                                 then the results won't be updated even after submitting this form
+                                 --></f:comment>
+                                <input type="hidden"
+                                       name="no_cache"
+                                       value="1">
+
                                 <button name="search-submit">Trouver</button>
                             </form>
                         </div>

+ 8 - 0
ot_templating/Resources/Private/Layouts/Classic/StructuresEvents.html

@@ -42,6 +42,14 @@
                                    class="datepicker datetimepicker"
                                    value="{ot:request.getArgument(argument: 'search-dateend')}" />
 
+                            <f:comment><!--
+                            Important: if the cache is not disabled,
+                             then the results won't be updated even after submitting this form
+                             --></f:comment>
+                            <input type="hidden"
+                                   name="no_cache"
+                                   value="1">
+
                             <button name="search-submit">Rechercher</button>
                         </form>
                     </div>

+ 8 - 0
ot_templating/Resources/Private/Layouts/Modern/Structures.html

@@ -33,6 +33,14 @@
                                                        placeholder="Où?"
                                                        value="{ot:request.getArgument(argument: 'search-loc')}"/>
 
+                                                <f:comment><!--
+                                                Important: if the cache is not disabled,
+                                                 then the results won't be updated even after submitting this form
+                                                 --></f:comment>
+                                                <input type="hidden"
+                                                       name="no_cache"
+                                                       value="1">
+
                                                 <button name="search-submit">Trouver</button>
                                             </form>
                                         </div>

+ 8 - 0
ot_templating/Resources/Private/Layouts/Modern/StructuresEvents.html

@@ -44,6 +44,14 @@
                                                    class="datepicker datetimepicker"
                                                    value="{ot:request.getArgument(argument: 'search-dateend')}" />
 
+                                            <f:comment><!--
+                                                Important: if the cache is not disabled,
+                                                 then the results won't be updated even after submitting this form
+                                                 --></f:comment>
+                                            <input type="hidden"
+                                                   name="no_cache"
+                                                   value="1">
+
                                             <button name="search-submit">Rechercher</button>
                                         </form>
                                     </div>

+ 8 - 0
ot_templating/Resources/Private/Partials/Classic/EventsIndex.html

@@ -26,6 +26,14 @@
                        class="datepicker datetimepicker"
                        value="{ot:request.getArgument(argument: 'search-dateend')}" />
 
+                <f:comment><!--
+                Important: if the cache is not disabled,
+                 then the results won't be updated even after submitting this form
+                 --></f:comment>
+                <input type="hidden"
+                       name="no_cache"
+                       value="1">
+
                 <button name="search-submit">Rechercher</button>
             </form>
         </div>

+ 8 - 0
ot_templating/Resources/Private/Partials/Modern/EventsIndex.html

@@ -26,6 +26,14 @@
                        class="datepicker datetimepicker"
                        value="{ot:request.getArgument(argument: 'search-dateend')}" />
 
+                <f:comment><!--
+                Important: if the cache is not disabled,
+                 then the results won't be updated even after submitting this form
+                 --></f:comment>
+                <input type="hidden"
+                       name="no_cache"
+                       value="1">
+
                 <button name="search-submit">Rechercher</button>
             </form>
         </div>