|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Christian Kuhn <lolli@schwarzbu.ch> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Garbage collection of caching framework cache backends. 00027 * 00028 * This task finds all configured caching framework caches and 00029 * calls the garbage collection of a cache if the cache backend 00030 * is configured to be cleaned. 00031 * 00032 * @author Christian Kuhn <lolli@schwarzbu.ch> 00033 * @package TYPO3 00034 * @subpackage scheduler 00035 */ 00036 class tx_scheduler_CachingFrameworkGarbageCollection extends tx_scheduler_Task { 00037 /** 00038 * Backend types that should be cleaned up, 00039 * set by additional field provider. 00040 * 00041 * @var array Selected backends to do garbage collection for 00042 */ 00043 public $selectedBackends = array(); 00044 00045 /** 00046 * Execute garbage collection, called by scheduler. 00047 * 00048 * @return void 00049 */ 00050 public function execute() { 00051 // Don't do anything if caching framework is not used at all 00052 if (t3lib_cache::isCachingFrameworkInitialized()) { 00053 // Global subarray with all configured caches 00054 $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']; 00055 00056 if (is_array($cacheConfigurations)) { 00057 // Iterate through configured caches and call garbage collection if 00058 // backend is within selected backends in additonal field of task 00059 foreach ($cacheConfigurations as $cacheName => $cacheConfiguration) { 00060 // The cache backend used for this cache 00061 $usedCacheBackend = $cacheConfiguration['backend']; 00062 00063 if (in_array($usedCacheBackend, $this->selectedBackends)) { 00064 $this->callGarbageCollectionOfCache($cacheName, $cacheConfiguration); 00065 } 00066 } 00067 } 00068 } 00069 00070 return(TRUE); 00071 } 00072 00073 /** 00074 * Get an instance of cache and call garbage collection 00075 * 00076 * @param string Cache name 00077 * @param array Cache configuration 00078 */ 00079 protected function callGarbageCollectionOfCache($cacheName, array $cacheConfiguration) { 00080 // Get existing cache instance or create a new one 00081 try { 00082 $cache = $GLOBALS['typo3CacheManager']->getCache($cacheName); 00083 } catch (t3lib_cache_exception_NoSuchCache $exception) { 00084 $GLOBALS['typo3CacheFactory']->create( 00085 $cacheName, 00086 $cacheConfiguration['frontend'], 00087 $cacheConfiguration['backend'], 00088 $cacheConfiguration['options'] 00089 ); 00090 $cache = $GLOBALS['typo3CacheManager']->getCache($cacheName); 00091 } 00092 00093 // Call garbage collection of this cache 00094 $cache->collectGarbage(); 00095 } 00096 } // End of class 00097 00098 if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_cachingframeworkgarbagecollection.php']) { 00099 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_cachingframeworkgarbagecollection.php']); 00100 } 00101 00102 ?>
1.8.0