diff --git a/typo3/sysext/core/Classes/Cache/Backend/TransientBackendInterface.php b/typo3/sysext/core/Classes/Cache/Backend/TransientBackendInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..720f7f23da092aa0bb55882b0936b9031fa55e8d --- /dev/null +++ b/typo3/sysext/core/Classes/Cache/Backend/TransientBackendInterface.php @@ -0,0 +1,35 @@ +<?php +namespace TYPO3\CMS\Core\Cache\Backend; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +/** + * A contract for a cache backends which store variables in volatile + * memory and as such support receiving any variable type to store. + * + * Note: respect for this contract is up to each individual frontend. + * The contract can be respected for a small performance boost, but + * the result is marginal except for cases with huge serialized + * data sets. + * + * Respected by the VariableFrontend which checks if the backend + * has this interface, in which case it allows the backend to store + * the value directly without serializing it to a string, and does + * not attempt to unserialize the string on every get() request. + * + * @api + */ +interface TransientBackendInterface extends BackendInterface +{ +} diff --git a/typo3/sysext/core/Classes/Cache/Backend/TransientMemoryBackend.php b/typo3/sysext/core/Classes/Cache/Backend/TransientMemoryBackend.php index 32e366c5946475588ef57d5b880782ef71bf5ecc..f80a3233323e85c858c33251985496c38a13c148 100644 --- a/typo3/sysext/core/Classes/Cache/Backend/TransientMemoryBackend.php +++ b/typo3/sysext/core/Classes/Cache/Backend/TransientMemoryBackend.php @@ -20,7 +20,7 @@ namespace TYPO3\CMS\Core\Cache\Backend; * This file is a backport from FLOW3 * @api */ -class TransientMemoryBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend implements \TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface +class TransientMemoryBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend implements TaggableBackendInterface, TransientBackendInterface { /** * @var array @@ -49,9 +49,6 @@ class TransientMemoryBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBacke if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) { throw new \TYPO3\CMS\Core\Cache\Exception('No cache frontend has been set yet via setCache().', 1238244992); } - if (!is_string($data)) { - throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1238244993); - } $this->entries[$entryIdentifier] = $data; foreach ($tags as $tag) { $this->tagsAndEntries[$tag][$entryIdentifier] = true; diff --git a/typo3/sysext/core/Classes/Cache/Frontend/VariableFrontend.php b/typo3/sysext/core/Classes/Cache/Frontend/VariableFrontend.php index e03628be96654d178c5121d84d03f3d6d3361b7d..b79463d12afb5a12ac174635c4a7beff63053c18 100644 --- a/typo3/sysext/core/Classes/Cache/Frontend/VariableFrontend.php +++ b/typo3/sysext/core/Classes/Cache/Frontend/VariableFrontend.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Cache\Frontend; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -57,7 +58,10 @@ class VariableFrontend extends AbstractFrontend GeneralUtility::callUserFunction($_funcRef, $params, $this); } } - $this->backend->set($entryIdentifier, serialize($variable), $tags, $lifetime); + if (!$this->backend instanceof TransientBackendInterface) { + $variable = serialize($variable); + } + $this->backend->set($entryIdentifier, $variable, $tags, $lifetime); } /** @@ -81,7 +85,7 @@ class VariableFrontend extends AbstractFrontend if ($rawResult === false) { return false; } else { - return unserialize($rawResult); + return $this->backend instanceof TransientBackendInterface ? $rawResult : unserialize($rawResult); } } @@ -104,7 +108,7 @@ class VariableFrontend extends AbstractFrontend foreach ($identifiers as $identifier) { $rawResult = $this->backend->get($identifier); if ($rawResult !== false) { - $entries[] = unserialize($rawResult); + $entries[] = $this->backend instanceof TransientBackendInterface ? $rawResult : unserialize($rawResult); } } return $entries;