/**
  * Clears the cache based on the command $cacheCmd.
  *
  * $cacheCmd='pages':	Clears cache for all pages. Requires admin-flag to
  * be set for BE_USER.
  *
  * $cacheCmd='all':		Clears all cache_tables. This is necessary if
  * templates are updated. Requires admin-flag to be set for BE_USER.
  *
  * $cacheCmd=[integer]:	Clears cache for the page pointed to by $cacheCmd
  * (an integer).
  *
  * Can call a list of post processing functions as defined in
  * $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']
  * (numeric array with values being the function references, called by
  * t3lib_div::callUserFunction()).
  *
  * Note: The following cache_* are intentionally not cleared by
  * $cacheCmd='all':
  *
  * - cache_md5params:	Clearing this table would destroy all simulateStatic
  *						 URLs, simulates file name and RDCT redirects.
  * - cache_imagesizes:	Clearing this table would cause a lot of unneeded
  *						 Imagemagick calls because the size informations have
  *						 to be fetched again after clearing.
  * - cache_extensions:	Clearing this table would make the extension manager
  *						 unusable until a new extension list is fetched from
  *						 the TER.
  *
  * @param	string		the cache command, see above description
  * @return	void
  */
 public function clear_cacheCmd($cacheCmd)
 {
     global $TYPO3_CONF_VARS;
     $this->BE_USER->writelog(3, 1, 0, 0, 'User %s has cleared the cache (cacheCmd=%s)', array($this->BE_USER->user['username'], $cacheCmd));
     // Clear cache for either ALL pages or ALL tables!
     switch ($cacheCmd) {
         case 'pages':
             if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
                 $this->internal_clearPageCache();
             }
             break;
         case 'all':
             if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
                 // Clear all caching framework caches if it is initialized:
                 // (it could be disabled by initialized by an extension)
                 if (t3lib_cache::isCachingFrameworkInitialized()) {
                     $GLOBALS['typo3CacheManager']->flushCaches();
                 }
                 if (TYPO3_UseCachingFramework) {
                     if (t3lib_extMgm::isLoaded('cms')) {
                         $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
                     }
                 } else {
                     if (t3lib_extMgm::isLoaded('cms')) {
                         $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
                         $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pagesection');
                     }
                     $this->internal_clearPageCache();
                     $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_hash');
                 }
                 // Clearing additional cache tables:
                 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) {
                     foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'] as $tableName) {
                         if (!preg_match('/[^[:alnum:]_]/', $tableName) && substr($tableName, -5) == 'cache') {
                             $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery($tableName);
                         } else {
                             throw new RuntimeException('TYPO3 Fatal Error: Trying to flush table "' . $tableName . '" with "Clear All Cache"', 1270853922);
                         }
                     }
                 }
             }
             if ($this->admin && $TYPO3_CONF_VARS['EXT']['extCache']) {
                 $this->removeCacheFiles();
             }
             break;
         case 'temp_CACHED':
             if ($this->admin && $TYPO3_CONF_VARS['EXT']['extCache']) {
                 $this->removeCacheFiles();
             }
             break;
     }
     // Clear cache for a page ID!
     if (t3lib_div::testInt($cacheCmd)) {
         if (t3lib_extMgm::isLoaded('cms')) {
             $list_cache = array($cacheCmd);
             // Call pre-processing function for clearing of cache for page ids:
             if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) {
                 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) {
                     $_params = array('pageIdArray' => &$list_cache, 'cacheCmd' => $cacheCmd, 'functionID' => 'clear_cacheCmd()');
                     // Returns the array of ids to clear, false if nothing should be cleared! Never an empty array!
                     t3lib_div::callUserFunction($funcName, $_params, $this);
                 }
             }
             // Delete cache for selected pages:
             if (is_array($list_cache)) {
                 if (TYPO3_UseCachingFramework) {
                     $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
                     $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
                     foreach ($list_cache as $pageId) {
                         $pageCache->flushByTag('pageId_' . (int) $pageId);
                         $pageSectionCache->flushByTag('pageId_' . (int) $pageId);
                     }
                 } else {
                     $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')');
                     $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')');
                     // Originally, cache_pagesection was not cleared with cache_pages!
                 }
             }
         }
     }
     // Call post processing function for clear-cache:
     if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) {
         $_params = array('cacheCmd' => $cacheCmd);
         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) {
             t3lib_div::callUserFunction($_funcRef, $_params, $this);
         }
     }
 }