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 ***************************************************************/
27 * A cache for any kinds of PHP variables
29 * This file is a backport from FLOW3
32 * @subpackage t3lib_cache
35 class t3lib_cache_frontend_VariableFrontend
extends t3lib_cache_frontend_AbstractFrontend
{
38 * Saves the value of a PHP variable in the cache. Note that the variable
39 * will be serialized if necessary.
41 * @param string $entryIdentifier An identifier used for this cache entry
42 * @param mixed $variable The variable to cache
43 * @param array $tags Tags to associate with this cache entry
44 * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
46 * @author Robert Lemke <robert@typo3.org>
47 * @author Karsten Dambekalns <karsten@typo3.org>
49 public function set($entryIdentifier, $variable, $tags = array(), $lifetime = NULL) {
50 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
51 throw new InvalidArgumentException(
52 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
57 foreach ($tags as $tag) {
58 if (!$this->isValidTag($tag)) {
59 throw new InvalidArgumentException(
60 '"' . $tag . '" is not a valid tag for a cache entry.',
66 $this->backend
->set($entryIdentifier, serialize($variable), $tags, $lifetime);
70 * Loads a variable value from the cache.
72 * @param string Identifier of the cache entry to fetch
73 * @return mixed The value
74 * @author Robert Lemke <robert@typo3.org>
75 * @throws t3lib_cache_exception_ClassAlreadyLoaded if the class already exists
77 public function get($entryIdentifier) {
78 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
79 throw new InvalidArgumentException(
80 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
85 return unserialize($this->backend
->get($entryIdentifier));
89 * Finds and returns all cache entries which are tagged by the specified tag.
91 * @param string $tag The tag to search for
92 * @return array An array with the content of all matching entries. An empty array if no entries matched
93 * @author Karsten Dambekalns <karsten@typo3.org>
95 public function getByTag($tag) {
96 if (!$this->isValidTag($tag)) {
97 throw new InvalidArgumentException(
98 '"' . $tag . '" is not a valid tag for a cache entry.',
104 $identifiers = $this->backend
->findIdentifiersByTag($tag);
106 foreach ($identifiers as $identifier) {
107 $entries[] = unserialize($this->backend
->get($identifier));
116 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_variablecache.php']) {
117 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_variablecache.php']);