TYPO3 API  SVNRelease
Cache.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
00006 *  All rights reserved
00007 *
00008 *  This class is a backport of the corresponding class of FLOW3.
00009 *  All credits go to the v5 team.
00010 *
00011 *  This script is part of the TYPO3 project. The TYPO3 project is
00012 *  free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  The GNU General Public License can be found at
00018 *  http://www.gnu.org/copyleft/gpl.html.
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 /**
00029  * Cache clearing helper functions
00030  *
00031  * @package Extbase
00032  * @subpackage Utility
00033  * @version $Id: Cache.php 1729 2009-11-25 21:37:20Z stucki $
00034  */
00035 class Tx_Extbase_Utility_Cache {
00036 
00037     /**
00038      * Clears the page cache
00039      *
00040      * @param mixed $pageIdsToClear (int) single or (array) multiple pageIds to clear the cache for
00041      * @return void
00042      */
00043     static public function clearPageCache($pageIdsToClear = NULL) {
00044         if ($pageIdsToClear !== NULL && !is_array($pageIdsToClear)) {
00045             $pageIdsToClear = array(intval($pageIdsToClear));
00046         }
00047 
00048         self::flushPageCache($pageIdsToClear);
00049         self::flushPageSectionCache($pageIdsToClear);
00050     }
00051 
00052     /**
00053      * Flushes cache_pages or cachinframework_cache_pages.
00054      *
00055      * @param array $pageIdsToClear pageIds to clear the cache for
00056      * @return void
00057      */
00058     static protected function flushPageCache($pageIds = NULL) {
00059         if (TYPO3_UseCachingFramework) {
00060             $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
00061 
00062             if ($pageIds !== NULL) {
00063                 foreach ($pageIds as $pageId) {
00064                     $pageCache->flushByTag('pageId_' . $pageId);
00065                 }
00066             } else {
00067                 $pageCache->flush();
00068             }
00069         } elseif ($pageIds !== NULL) {
00070             $GLOBALS['TYPO3_DB']->exec_DELETEquery(
00071                 'cache_pages',
00072                 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($pageIds)) . ')'
00073             );
00074         } else {
00075             $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pages');
00076         }
00077     }
00078 
00079     /**
00080      * Flushes cache_pagesection or cachingframework_cache_pagesection.
00081      *
00082      * @param array $pageIdsToClear pageIds to clear the cache for
00083      * @return void
00084      */
00085     static protected function flushPageSectionCache($pageIds = NULL) {
00086         if (TYPO3_UseCachingFramework) {
00087             $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
00088 
00089             if ($pageIds !== NULL) {
00090                 foreach ($pageIds as $pageId) {
00091                     $pageSectionCache->flushByTag('pageId_' . $pageId);
00092                 }
00093             } else {
00094                 $pageSectionCache->flush();
00095             }
00096         } elseif ($pageIds !== NULL) {
00097             $GLOBALS['TYPO3_DB']->exec_DELETEquery(
00098                 'cache_pagesection',
00099                 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($pageIds)) . ')'
00100             );
00101         } else {
00102             $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pagesection');
00103         }
00104     }
00105 }
00106 ?>