2 /***************************************************************
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
29 * This file is a backport from FLOW3
32 * @subpackage t3lib_cache
35 abstract class t3lib_cache_frontend_AbstractFrontend
implements t3lib_cache_frontend_Frontend
{
38 * @var string Identifies this cache
40 protected $identifier;
43 * @var t3lib_cache_backend_AbstractBackend
48 * Constructs the cache
50 * @param string A identifier which describes this cache
51 * @param t3lib_cache_backend_Backend Backend to be used for this cache
52 * @author Robert Lemke <robert@typo3.org>
53 * @throws InvalidArgumentException if the identifier doesn't match PATTERN_ENTRYIDENTIFIER
56 public function __construct($identifier, t3lib_cache_backend_Backend
$backend) {
57 if (!preg_match(self
::PATTERN_ENTRYIDENTIFIER
, $identifier)) {
58 throw new InvalidArgumentException('"' . $identifier . '" is not a valid cache identifier.', 1203584729);
61 $this->identifier
= $identifier;
62 $this->backend
= $backend;
63 $this->backend
->setCache($this);
67 * Returns this cache's identifier
69 * @return string The identifier for this cache
70 * @author Robert Lemke <robert@typo3.org>
72 public function getIdentifier() {
73 return $this->identifier
;
77 * Returns the backend used by this cache
79 * @return t3lib_cache_backend_Backend The backend used by this cache
80 * @author Robert Lemke <robert@typo3.org>
82 public function getBackend() {
83 return $this->backend
;
87 * Checks if a cache entry with the specified identifier exists.
89 * @param string $entryIdentifier An identifier specifying the cache entry
90 * @return boolean TRUE if such an entry exists, FALSE if not
91 * @author Robert Lemke <robert@typo3.org>
92 * @author Karsten Dambekalns <karsten@typo3.org>
94 public function has($entryIdentifier) {
95 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
96 throw new InvalidArgumentException(
97 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
102 return $this->backend
->has($entryIdentifier);
106 * Removes the given cache entry from the cache.
108 * @param string $entryIdentifier An identifier specifying the cache entry
109 * @return boolean TRUE if such an entry exists, FALSE if not
110 * @author Sebastian Kurfuerst <sebastian@typo3.org>
111 * @author Karsten Dambekalns <karsten@typo3.org>
113 public function remove($entryIdentifier) {
114 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
115 throw new InvalidArgumentException(
116 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
121 return $this->backend
->remove($entryIdentifier);
125 * Removes all cache entries of this cache.
128 * @author Robert Lemke <robert@typo3.org>
130 public function flush() {
131 $this->backend
->flush();
135 * Removes all cache entries of this cache which are tagged by the specified tag.
137 * @param string $tag The tag the entries must have
139 * @author Robert Lemke <robert@typo3.org>
140 * @author Karsten Dambekalns <karsten@typo3.org>
142 public function flushByTag($tag) {
143 if (!$this->isValidTag($tag)) {
144 throw new InvalidArgumentException(
145 '"' . $tag . '" is not a valid tag for a cache entry.',
150 $this->backend
->flushByTag($tag);
154 * Removes all cache entries of this cache which are tagged by the specified tag.
156 * @param array Array of tags to search for and to remove the cache entries, the "*" wildcard is supported
158 * @author Ingo Renner <ingo@typo3.org>
160 public function flushByTags(array $tags) {
161 $this->backend
->flushByTags($tags);
165 * Does garbage collection
168 * @author Karsten Dambekalns <karsten@typo3.org>
170 public function collectGarbage() {
171 $this->backend
->collectGarbage();
175 * Renders a tag which can be used to mark a cache entry as "depends on this class".
176 * Whenever the specified class is modified, all cache entries tagged with the
179 * If an empty string is specified as class name, the returned tag means
180 * "depends on any class".
182 * @param string The class name
183 * @return string Class Tag
184 * @author Robert Lemke <robert@typo3.org>
186 public function getClassTag($className = '') {
187 return ($className === '') ? self
::TAG_CLASS
: self
::TAG_CLASS
. str_replace('\\', '_', $className);
191 * Checks the validity of an entry identifier. Returns true if it's valid.
193 * @param string An identifier to be checked for validity
195 * @author Christian Jul Jensen <julle@typo3.org>
197 public function isValidEntryIdentifier($identifier) {
198 return preg_match(self
::PATTERN_ENTRYIDENTIFIER
, $identifier) === 1;
202 * Checks the validity of a tag. Returns true if it's valid.
204 * @param string An identifier to be checked for validity
206 * @author Robert Lemke <robert@typo3.org>
208 public function isValidTag($tag) {
209 return preg_match(self
::PATTERN_TAG
, $tag) === 1;
215 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']) {
216 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']);