2 namespace TYPO3\CMS\Core\Cache\Backend;
89 public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
$cache)
91 parent::setCache($cache);
93 $this->tagsTable =
'cf_' . $this->cacheIdentifier .
'_tags';
104 $this->identifierField = $this->cacheTable .
'.identifier';
105 $this->expiresField = $this->cacheTable .
'.expires';
106 $this->maximumLifetime = self::FAKED_UNLIMITED_EXPIRE -
$GLOBALS[
'EXEC_TIME'];
108 $this->tableJoin = $this->identifierField .
' = ' . $this->tagsTable .
'.identifier';
109 $this->expiredStatement = $this->expiresField .
' < ' . $GLOBALS[
'EXEC_TIME'];
110 $this->notExpiredStatement = $this->expiresField .
' >= ' . $GLOBALS[
'EXEC_TIME'];
124 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null)
127 if (!is_string($data)) {
128 throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException(
129 'The specified data is of type "' . gettype($data) .
'" but a string is expected.',
133 if (is_null($lifetime)) {
136 if ($lifetime === 0 || $lifetime > $this->maximumLifetime) {
139 $expires =
$GLOBALS[
'EXEC_TIME'] + $lifetime;
140 $this->
remove($entryIdentifier);
141 if ($this->compression) {
142 $data = gzcompress($data, $this->compressionLevel);
144 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery($this->cacheTable, array(
145 'identifier' => $entryIdentifier,
146 'expires' => $expires,
151 $fields[] =
'identifier';
154 foreach ($tags as $tag) {
156 $tagRow[] = $entryIdentifier;
158 $tagRows[] = $tagRow;
160 $GLOBALS[
'TYPO3_DB']->exec_INSERTmultipleRows($this->tagsTable, $fields, $tagRows);
170 public function get($entryIdentifier)
174 $cacheEntry =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
177 'identifier = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable) .
' AND ' . $this->notExpiredStatement
179 if (is_array($cacheEntry)) {
180 $cacheEntry = $cacheEntry[
'content'];
182 if ($this->compression && (
string)$cacheEntry !==
'') {
183 $cacheEntry = gzuncompress($cacheEntry);
185 return $cacheEntry !== null ? $cacheEntry :
false;
194 public function has($entryIdentifier)
198 $cacheEntries =
$GLOBALS[
'TYPO3_DB']->exec_SELECTcountRows(
201 'identifier = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable) .
' AND ' . $this->notExpiredStatement
203 if ($cacheEntries >= 1) {
216 public function remove($entryIdentifier)
219 $entryRemoved =
false;
220 $res =
$GLOBALS[
'TYPO3_DB']->exec_DELETEquery(
222 'identifier = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->cacheTable)
224 $GLOBALS[
'TYPO3_DB']->exec_DELETEquery(
226 'identifier = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($entryIdentifier, $this->tagsTable)
228 if (
$GLOBALS[
'TYPO3_DB']->sql_affected_rows($res) == 1) {
229 $entryRemoved =
true;
231 return $entryRemoved;
243 $cacheEntryIdentifiers = array();
244 $cacheEntryIdentifierRows =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetRows(
245 $this->identifierField,
247 $this->tagsTable .
'.tag = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable) .
' AND ' . $this->tableJoin .
' AND ' . $this->notExpiredStatement,
248 $this->identifierField
250 foreach ($cacheEntryIdentifierRows as $cacheEntryIdentifierRow) {
251 $cacheEntryIdentifiers[$cacheEntryIdentifierRow[
'identifier']] = $cacheEntryIdentifierRow[
'identifier'];
253 return $cacheEntryIdentifiers;
264 $GLOBALS[
'TYPO3_DB']->exec_TRUNCATEquery($this->cacheTable);
265 $GLOBALS[
'TYPO3_DB']->exec_TRUNCATEquery($this->tagsTable);
278 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded(
'dbal')) {
282 DELETE ' . $this->cacheTable .
', ' . $this->tagsTable .
'
283 FROM ' . $this->cacheTable .
' JOIN ' . $this->tagsTable .
' ON ' . $this->cacheTable .
'.identifier=' . $this->tagsTable .
'.identifier
284 WHERE ' . $this->tagsTable .
'.tag = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable)
297 $tagsTableWhereClause = $this->tagsTable .
'.tag = ' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($tag, $this->tagsTable);
298 $cacheEntryIdentifierRowsResource =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'DISTINCT identifier', $this->tagsTable, $tagsTableWhereClause);
299 $cacheEntryIdentifiers = array();
300 while ($cacheEntryIdentifierRow =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($cacheEntryIdentifierRowsResource)) {
301 $cacheEntryIdentifiers[] =
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($cacheEntryIdentifierRow[
'identifier'], $this->cacheTable);
303 $GLOBALS[
'TYPO3_DB']->sql_free_result($cacheEntryIdentifierRowsResource);
304 if (!empty($cacheEntryIdentifiers)) {
305 $deleteWhereClause =
'identifier IN (' . implode(
', ', $cacheEntryIdentifiers) .
')';
306 $GLOBALS[
'TYPO3_DB']->exec_DELETEquery($this->cacheTable, $deleteWhereClause);
307 $GLOBALS[
'TYPO3_DB']->exec_DELETEquery($this->tagsTable, $deleteWhereClause);
320 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded(
'dbal')) {
324 DELETE ' . $this->cacheTable .
', ' . $this->tagsTable .
'
325 FROM ' . $this->cacheTable .
' JOIN ' . $this->tagsTable .
' ON ' . $this->cacheTable .
'.identifier=' . $this->tagsTable .
'.identifier
326 WHERE ' . $this->expiredStatement
339 $cacheEntryIdentifierRowsResource =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'DISTINCT identifier', $this->cacheTable, $this->expiredStatement);
340 $cacheEntryIdentifiers = array();
341 while ($cacheEntryIdentifierRow =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($cacheEntryIdentifierRowsResource)) {
342 $cacheEntryIdentifiers[] =
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($cacheEntryIdentifierRow[
'identifier'], $this->tagsTable);
344 $GLOBALS[
'TYPO3_DB']->sql_free_result($cacheEntryIdentifierRowsResource);
346 if (!empty($cacheEntryIdentifiers)) {
347 $GLOBALS[
'TYPO3_DB']->exec_DELETEquery($this->tagsTable,
'identifier IN (' . implode(
', ', $cacheEntryIdentifiers) .
')');
350 $GLOBALS[
'TYPO3_DB']->exec_DELETEquery($this->cacheTable, $this->expiredStatement);
407 if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
408 throw new \TYPO3\CMS\Core\Cache\Exception(
'No cache frontend has been set via setCache() yet.', 1236518288);
421 $cacheTableSql = file_get_contents(
422 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
'core') .
423 'Resources/Private/Sql/Cache/Backend/Typo3DatabaseBackendCache.sql'
425 $requiredTableStructures = str_replace(
'###CACHE_TABLE###', $this->cacheTable, $cacheTableSql) . LF . LF;
426 $tagsTableSql = file_get_contents(
427 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
'core') .
428 'Resources/Private/Sql/Cache/Backend/Typo3DatabaseBackendTags.sql'
430 $requiredTableStructures .= str_replace(
'###TAGS_TABLE###', $this->tagsTable, $tagsTableSql) . LF;
431 return $requiredTableStructures;