|
TYPO3 API
SVNRelease
|
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 * An abstract caching backend 00027 * 00028 * This file is a backport from FLOW3 00029 * 00030 * @author Ingo Renner <ingo@typo3.org> 00031 * @package TYPO3 00032 * @subpackage t3lib_cache 00033 * @api 00034 * @version $Id: class.t3lib_cache_backend_abstractbackend.php 10121 2011-01-18 20:15:30Z ohader $ 00035 */ 00036 abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_Backend { 00037 00038 const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'; 00039 const UNLIMITED_LIFETIME = 0; 00040 00041 /** 00042 * Reference to the cache which uses this backend 00043 * 00044 * @var t3lib_cache_frontend_Frontend 00045 */ 00046 protected $cache; 00047 00048 /** 00049 * @var string 00050 */ 00051 protected $cacheIdentifier; 00052 00053 /** 00054 * Default lifetime of a cache entry in seconds 00055 * 00056 * @var integer 00057 */ 00058 protected $defaultLifetime = 3600; 00059 00060 /** 00061 * Constructs this backend 00062 * 00063 * @param array $options Configuration options - depends on the actual backend 00064 * @author Robert Lemke <robert@typo3.org> 00065 */ 00066 public function __construct(array $options = array()) { 00067 if (is_array($options) || $options instanceof ArrayAccess) { 00068 foreach ($options as $optionKey => $optionValue) { 00069 $methodName = 'set' . ucfirst($optionKey); 00070 if (method_exists($this, $methodName)) { 00071 $this->$methodName($optionValue); 00072 } else { 00073 throw new InvalidArgumentException('Invalid cache backend option "' . $optionKey . '" for backend of type "' . get_class($this) . '"', 1235837747); 00074 } 00075 } 00076 } 00077 } 00078 00079 /** 00080 * Sets a reference to the cache frontend which uses this backend 00081 * 00082 * @param t3lib_cache_frontend_Frontend The frontend for this backend 00083 * @return void 00084 * @author Robert Lemke <robert@typo3.org> 00085 */ 00086 public function setCache(t3lib_cache_frontend_Frontend $cache) { 00087 $this->cache = $cache; 00088 $this->cacheIdentifier = $this->cache->getIdentifier(); 00089 } 00090 00091 /** 00092 * Sets the default lifetime for this cache backend 00093 * 00094 * @param integer $defaultLifetime Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime. 00095 * @return void 00096 * @author Karsten Dambekalns <karsten@typo3.org> 00097 */ 00098 public function setDefaultLifetime($defaultLifetime) { 00099 if (!is_int($defaultLifetime) || $defaultLifetime < 0) { 00100 throw new InvalidArgumentException( 00101 'The default lifetime must be given as a positive integer.', 00102 1233072774 00103 ); 00104 } 00105 00106 $this->defaultLifetime = $defaultLifetime; 00107 } 00108 00109 /** 00110 * Calculates the expiry time by the given lifetime. If no lifetime is 00111 * specified, the default lifetime is used. 00112 * 00113 * @param integer $lifetime The lifetime in seconds 00114 * @return \DateTime The expiry time 00115 * @author Robert Lemke <robert@typo3.org> 00116 * @internal 00117 */ 00118 protected function calculateExpiryTime($lifetime = NULL) { 00119 if ($lifetime === self::UNLIMITED_LIFETIME || ($lifetime === NULL && $this->defaultLifetime === self::UNLIMITED_LIFETIME)) { 00120 $expiryTime = new DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new DateTimeZone('UTC')); 00121 } else { 00122 if ($lifetime === NULL) { 00123 $lifetime = $this->defaultLifetime; 00124 } 00125 $expiryTime = new DateTime('now +' . $lifetime . ' seconds', new DateTimeZone('UTC')); 00126 } 00127 00128 return $expiryTime; 00129 } 00130 00131 00132 } 00133 00134 00135 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/backend/class.t3lib_cache_backend_abstractbackend.php'])) { 00136 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/backend/class.t3lib_cache_backend_abstractbackend.php']); 00137 } 00138 00139 ?>
1.8.0