!!! Fixed issue #10614: update the caching framework to the latest version as in...
[Packages/TYPO3.CMS.git] / t3lib / cache / backend / class.t3lib_cache_backend_abstractbackend.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 * An abstract caching backend
27 *
28 * This file is a backport from FLOW3
29 *
30 * @author Ingo Renner <ingo@typo3.org>
31 * @package TYPO3
32 * @subpackage t3lib_cache
33 * @version $Id$
34 */
35 abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_Backend {
36
37 /**
38 * Reference to the cache which uses this backend
39 *
40 * @var t3lib_cache_frontend_Frontend
41 */
42 protected $cache;
43
44 /**
45 * Default lifetime of a cache entry in seconds
46 *
47 * @var integer
48 */
49 protected $defaultLifetime = 3600;
50
51 /**
52 * Constructs this backend
53 *
54 * @param mixed Configuration options - depends on the actual backend
55 * @author Robert Lemke <robert@typo3.org>
56 */
57 public function __construct(array $options = array()) {
58 if (is_array($options) || $options instanceof ArrayAccess) {
59 foreach ($options as $optionKey => $optionValue) {
60 $methodName = 'set' . ucfirst($optionKey);
61 if (method_exists($this, $methodName)) {
62 $this->$methodName($optionValue);
63 } else {
64 throw new InvalidArgumentException('Invalid cache backend option "' . $optionKey . '" for backend of type "' . get_class($this) . '"', 1235837747);
65 }
66 }
67 }
68 }
69
70 /**
71 * Sets a reference to the cache frontend which uses this backend
72 *
73 * @param t3lib_cache_frontend_Frontend The frontend for this backend
74 * @return void
75 * @author Robert Lemke <robert@typo3.org>
76 */
77 public function setCache(t3lib_cache_frontend_Frontend $cache) {
78 $this->cache = $cache;
79 }
80
81 /**
82 * Sets the default lifetime for this cache backend
83 *
84 * @param integer $defaultLifeTime Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
85 * @return void
86 * @author Karsten Dambekalns <karsten@typo3.org>
87 */
88 public function setDefaultLifetime($defaultLifetime) {
89 if (!is_int($defaultLifetime) || $defaultLifetime < 0) {
90 throw new InvalidArgumentException(
91 'The default lifetime must be given as a positive integer.',
92 1233072774
93 );
94 }
95
96 $this->defaultLifetime = $defaultLifetime;
97 }
98
99 }
100
101
102 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/backend/class.t3lib_cache_backend_abstractbackend.php']) {
103 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/backend/class.t3lib_cache_backend_abstractbackend.php']);
104 }
105
106 ?>