Fixed bug #10454: t3lib_div::makeInstanceClassName() allows to bypass checks for...
[Packages/TYPO3.CMS.git] / t3lib / cache / class.t3lib_cache_variablecache.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * A cache for any kinds of PHP variables
28 *
29 * This file is a backport from FLOW3
30 *
31 * @package TYPO3
32 * @subpackage t3lib_cache
33 * @version $Id$
34 */
35 class t3lib_cache_VariableCache extends t3lib_cache_AbstractCache {
36
37 /**
38 * Saves the value of a PHP variable in the cache. Note that the variable
39 * will be serialized if necessary.
40 *
41 * @param string An identifier used for this cache entry
42 * @param mixed The variable to cache
43 * @param array Tags to associate with this cache entry
44 * @return void
45 * @author Robert Lemke <robert@typo3.org>
46 */
47 public function set($entryIdentifier, $variable, array $tags = array(), $lifetime = null) {
48 $this->backend->set($entryIdentifier, serialize($variable), $tags, $lifetime);
49 }
50
51 /**
52 * Loads a variable value from the cache.
53 *
54 * @param string Identifier of the cache entry to fetch
55 * @return mixed The value
56 * @author Robert Lemke <robert@typo3.org>
57 * @throws t3lib_cache_exception_ClassAlreadyLoaded if the class already exists
58 */
59 public function get($entryIdentifier) {
60 return unserialize($this->backend->get($entryIdentifier));
61 }
62
63 /**
64 * Checks if a cache entry with the specified identifier exists.
65 *
66 * @param string An identifier specifying the cache entry
67 * @return boolean TRUE if such an entry exists, FALSE if not
68 * @author Robert Lemke <robert@typo3.org>
69 */
70 public function has($entryIdentifier) {
71 return $this->backend->has($entryIdentifier);
72 }
73
74 /**
75 * Removes the given cache entry from the cache.
76 *
77 * @param string An identifier specifying the cache entry
78 * @return boolean TRUE if such an entry exists, FALSE if not
79 * @author Sebastian Kurfuerst <sebastian@typo3.org>
80 */
81 public function remove($entryIdentifier) {
82 return $this->backend->remove($entryIdentifier);
83 }
84 }
85
86
87 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_variablecache.php']) {
88 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_variablecache.php']);
89 }
90
91 ?>