|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Ingo Renner <ingo@typo3.org> 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 /** 00027 * An abstract cache 00028 * 00029 * This file is a backport from FLOW3 00030 * 00031 * @package TYPO3 00032 * @subpackage t3lib_cache 00033 * @api 00034 * @version $Id: class.t3lib_cache_frontend_abstractfrontend.php 10121 2011-01-18 20:15:30Z ohader $ 00035 */ 00036 abstract class t3lib_cache_frontend_AbstractFrontend implements t3lib_cache_frontend_Frontend { 00037 00038 /** 00039 * @var string Identifies this cache 00040 */ 00041 protected $identifier; 00042 00043 /** 00044 * @var t3lib_cache_backend_AbstractBackend 00045 */ 00046 protected $backend; 00047 00048 /** 00049 * Constructs the cache 00050 * 00051 * @param string A identifier which describes this cache 00052 * @param t3lib_cache_backend_Backend Backend to be used for this cache 00053 * @author Robert Lemke <robert@typo3.org> 00054 * @throws InvalidArgumentException if the identifier doesn't match PATTERN_ENTRYIDENTIFIER 00055 * @internal 00056 */ 00057 public function __construct($identifier, t3lib_cache_backend_Backend $backend) { 00058 if (!preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier)) { 00059 throw new InvalidArgumentException('"' . $identifier . '" is not a valid cache identifier.', 1203584729); 00060 } 00061 00062 $this->identifier = $identifier; 00063 $this->backend = $backend; 00064 $this->backend->setCache($this); 00065 } 00066 00067 /** 00068 * Returns this cache's identifier 00069 * 00070 * @return string The identifier for this cache 00071 * @author Robert Lemke <robert@typo3.org> 00072 */ 00073 public function getIdentifier() { 00074 return $this->identifier; 00075 } 00076 00077 /** 00078 * Returns the backend used by this cache 00079 * 00080 * @return t3lib_cache_backend_Backend The backend used by this cache 00081 * @author Robert Lemke <robert@typo3.org> 00082 */ 00083 public function getBackend() { 00084 return $this->backend; 00085 } 00086 00087 /** 00088 * Checks if a cache entry with the specified identifier exists. 00089 * 00090 * @param string $entryIdentifier An identifier specifying the cache entry 00091 * @return boolean TRUE if such an entry exists, FALSE if not 00092 * @author Robert Lemke <robert@typo3.org> 00093 * @author Karsten Dambekalns <karsten@typo3.org> 00094 */ 00095 public function has($entryIdentifier) { 00096 if (!$this->isValidEntryIdentifier($entryIdentifier)) { 00097 throw new InvalidArgumentException( 00098 '"' . $entryIdentifier . '" is not a valid cache entry identifier.', 00099 1233058486 00100 ); 00101 } 00102 00103 return $this->backend->has($entryIdentifier); 00104 } 00105 00106 /** 00107 * Removes the given cache entry from the cache. 00108 * 00109 * @param string $entryIdentifier An identifier specifying the cache entry 00110 * @return boolean TRUE if such an entry exists, FALSE if not 00111 * @author Sebastian Kurfürst <sebastian@typo3.org> 00112 * @author Karsten Dambekalns <karsten@typo3.org> 00113 */ 00114 public function remove($entryIdentifier) { 00115 if (!$this->isValidEntryIdentifier($entryIdentifier)) { 00116 throw new InvalidArgumentException( 00117 '"' . $entryIdentifier . '" is not a valid cache entry identifier.', 00118 1233058495 00119 ); 00120 } 00121 00122 return $this->backend->remove($entryIdentifier); 00123 } 00124 00125 /** 00126 * Removes all cache entries of this cache. 00127 * 00128 * @return void 00129 * @author Robert Lemke <robert@typo3.org> 00130 */ 00131 public function flush() { 00132 $this->backend->flush(); 00133 } 00134 00135 /** 00136 * Removes all cache entries of this cache which are tagged by the specified tag. 00137 * 00138 * @param string $tag The tag the entries must have 00139 * @return void 00140 * @author Robert Lemke <robert@typo3.org> 00141 * @author Karsten Dambekalns <karsten@typo3.org> 00142 */ 00143 public function flushByTag($tag) { 00144 if (!$this->isValidTag($tag)) { 00145 throw new InvalidArgumentException( 00146 '"' . $tag . '" is not a valid tag for a cache entry.', 00147 1233057359 00148 ); 00149 } 00150 00151 $this->backend->flushByTag($tag); 00152 } 00153 00154 /** 00155 * Removes all cache entries of this cache which are tagged by the specified tag. 00156 * 00157 * @param array Array of tags to search for and to remove the cache entries, the "*" wildcard is supported 00158 * @return void 00159 * @author Ingo Renner <ingo@typo3.org> 00160 */ 00161 public function flushByTags(array $tags) { 00162 $this->backend->flushByTags($tags); 00163 } 00164 00165 /** 00166 * Does garbage collection 00167 * 00168 * @return void 00169 * @author Karsten Dambekalns <karsten@typo3.org> 00170 */ 00171 public function collectGarbage() { 00172 $this->backend->collectGarbage(); 00173 } 00174 00175 /** 00176 * Renders a tag which can be used to mark a cache entry as "depends on this class". 00177 * Whenever the specified class is modified, all cache entries tagged with the 00178 * class are flushed. 00179 * 00180 * If an empty string is specified as class name, the returned tag means 00181 * "depends on any class". 00182 * 00183 * @param string The class name 00184 * @return string Class Tag 00185 * @author Robert Lemke <robert@typo3.org> 00186 */ 00187 public function getClassTag($className = '') { 00188 return ($className === '') ? self::TAG_CLASS : self::TAG_CLASS . str_replace('\\', '_', $className); 00189 } 00190 00191 /** 00192 * Checks the validity of an entry identifier. Returns true if it's valid. 00193 * 00194 * @param string $identifier An identifier to be checked for validity 00195 * @return boolean 00196 * @author Christian Jul Jensen <julle@typo3.org> 00197 */ 00198 public function isValidEntryIdentifier($identifier) { 00199 return preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) === 1; 00200 } 00201 00202 /** 00203 * Checks the validity of a tag. Returns true if it's valid. 00204 * 00205 * @param string $tag An identifier to be checked for validity 00206 * @return boolean 00207 * @author Robert Lemke <robert@typo3.org> 00208 */ 00209 public function isValidTag($tag) { 00210 return preg_match(self::PATTERN_TAG, $tag) === 1; 00211 } 00212 00213 } 00214 00215 00216 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'])) { 00217 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']); 00218 } 00219 00220 ?>
1.8.0