Updated the caching framework to the according FLOW3 revision 2616
[Packages/TYPO3.CMS.git] / t3lib / cache / frontend / class.t3lib_cache_frontend_stringfrontend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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 frontend for strings. Nothing else.
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_frontend_StringFrontend extends t3lib_cache_frontend_AbstractFrontend {
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 string The variable to cache
43 * @param array Tags to associate with this cache entry
44 * @param integer Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
45 * @return void
46 * @author Karsten Dambekalns <karsten@typo3.org>
47 */
48 public function set($entryIdentifier, $string, $tags = array(), $lifetime = NULL) {
49 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
50 throw new InvalidArgumentException(
51 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
52 1233057566
53 );
54 }
55
56 if (!is_string($string)) {
57 throw new t3lib_cache_exception_InvalidData(
58 'Only strings can be digested by the StringCache. Thanks.',
59 1222808333
60 );
61 }
62
63 foreach ($tags as $tag) {
64 if (!$this->isValidTag($tag)) {
65 throw new InvalidArgumentException(
66 '"' . $tag . '" is not a valid tag for a cache entry.',
67 1233057512
68 );
69 }
70 }
71
72 $this->backend->set($entryIdentifier, $string, $tags, $lifetime);
73 }
74
75 /**
76 * Loads a variable value from the cache.
77 *
78 * @param string Identifier of the cache entry to fetch
79 * @return string The value
80 * @author Karsten Dambekalns <karsten@typo3.org>
81 */
82 public function get($entryIdentifier) {
83 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
84 throw new InvalidArgumentException(
85 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
86 1233057752
87 );
88 }
89
90 return $this->backend->get($entryIdentifier);
91 }
92
93 /**
94 * Finds and returns all cache entries which are tagged by the specified tag.
95 *
96 * @param string $tag The tag to search for
97 * @return array An array with the content of all matching entries. An empty array if no entries matched
98 * @author Karsten Dambekalns <karsten@typo3.org>
99 */
100 public function getByTag($tag) {
101 if (!$this->isValidTag($tag)) {
102 throw new InvalidArgumentException(
103 '"' . $tag . '" is not a valid tag for a cache entry.',
104 1233057772
105 );
106 }
107
108 $entries = array();
109 $identifiers = $this->backend->findIdentifiersByTag($tag);
110
111 foreach ($identifiers as $identifier) {
112 $entries[] = $this->backend->get($identifier);
113 }
114
115 return $entries;
116 }
117
118 }
119
120
121 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_stringcache.php']) {
122 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_stringcache.php']);
123 }
124
125 ?>