TYPO3 API  SVNRelease
class.t3lib_cache_frontend_stringfrontend.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2009-2011 Ingo Renner <ingo@typo3.org>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *
00017  *  This script is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  This copyright notice MUST APPEAR in all copies of the script!
00023  ***************************************************************/
00024 
00025 
00026 /**
00027  * A cache frontend for strings. Nothing else.
00028  *
00029  * This file is a backport from FLOW3
00030  *
00031  * @package TYPO3
00032  * @subpackage t3lib_cache
00033  * @api
00034  * @version $Id: class.t3lib_cache_frontend_stringfrontend.php 10121 2011-01-18 20:15:30Z ohader $
00035  */
00036 class t3lib_cache_frontend_StringFrontend extends t3lib_cache_frontend_AbstractFrontend {
00037 
00038     /**
00039      * Saves the value of a PHP variable in the cache. Note that the variable
00040      * will be serialized if necessary.
00041      *
00042      * @param string An identifier used for this cache entry
00043      * @param string The variable to cache
00044      * @param array Tags to associate with this cache entry
00045      * @param integer Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
00046      * @return void
00047      * @author Karsten Dambekalns <karsten@typo3.org>
00048      */
00049     public function set($entryIdentifier, $string, $tags = array(), $lifetime = NULL) {
00050         if (!$this->isValidEntryIdentifier($entryIdentifier)) {
00051             throw new InvalidArgumentException(
00052                 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
00053                 1233057566
00054             );
00055         }
00056 
00057         if (!is_string($string)) {
00058             throw new t3lib_cache_exception_InvalidData(
00059                 'Given data is of type "' . gettype($string) . '", but a string is expected for string cache.',
00060                 1222808333
00061             );
00062         }
00063 
00064         foreach ($tags as $tag) {
00065             if (!$this->isValidTag($tag)) {
00066                 throw new InvalidArgumentException(
00067                     '"' . $tag . '" is not a valid tag for a cache entry.',
00068                     1233057512
00069                 );
00070             }
00071         }
00072 
00073         $this->backend->set($entryIdentifier, $string, $tags, $lifetime);
00074     }
00075 
00076     /**
00077      * Loads a variable value from the cache.
00078      *
00079      * @param string Identifier of the cache entry to fetch
00080      * @return string The value
00081      * @author Karsten Dambekalns <karsten@typo3.org>
00082      */
00083     public function get($entryIdentifier) {
00084         if (!$this->isValidEntryIdentifier($entryIdentifier)) {
00085             throw new InvalidArgumentException(
00086                 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
00087                 1233057752
00088             );
00089         }
00090 
00091         return $this->backend->get($entryIdentifier);
00092     }
00093 
00094     /**
00095      * Finds and returns all cache entries which are tagged by the specified tag.
00096      *
00097      * @param string $tag The tag to search for
00098      * @return array An array with the content of all matching entries. An empty array if no entries matched
00099      * @author Karsten Dambekalns <karsten@typo3.org>
00100      */
00101     public function getByTag($tag) {
00102         if (!$this->isValidTag($tag)) {
00103             throw new InvalidArgumentException(
00104                 '"' . $tag . '" is not a valid tag for a cache entry.',
00105                 1233057772
00106             );
00107         }
00108 
00109         $entries = array();
00110         $identifiers = $this->backend->findIdentifiersByTag($tag);
00111 
00112         foreach ($identifiers as $identifier) {
00113             $entries[] = $this->backend->get($identifier);
00114         }
00115 
00116         return $entries;
00117     }
00118 
00119 }
00120 
00121 
00122 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_stringcache.php'])) {
00123     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_stringcache.php']);
00124 }
00125 
00126 ?>