2 /***************************************************************
5 * (c) 2008-2009 Ingo Renner <ingo@typo3.org>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * This cache factory takes care of instantiating a cache frontend and injecting
28 * a certain cache backend. After creation of the new cache, the cache object
29 * is registered at the cache manager.
31 * This file is a backport from FLOW3
34 * @subpackage t3lib_cache
37 class t3lib_cache_Factory
implements t3lib_Singleton
{
40 * A reference to the cache manager
42 * @var t3lib_cache_Manager
44 protected $cacheManager;
47 * Injects the cache manager.
49 * This is called by the cache manager itself
51 * @param t3lib_cache_Manager The cache manager
53 * @author Robert Lemke <robert@typo3.org>
56 public function setCacheManager(t3lib_cache_Manager
$cacheManager) {
57 $this->cacheManager
= $cacheManager;
61 * Factory method which creates the specified cache along with the specified kind of backend.
62 * After creating the cache, it will be registered at the cache manager.
64 * @param string The name / identifier of the cache to create
65 * @param string Name of the cache frontend
66 * @param string Name of the cache backend
67 * @param array (optional) Array of backend options
68 * @return t3lib_cache_frontend_Frontend The created cache frontend
69 * @author Robert Lemke <robert@typo3.org>
71 public function create($cacheIdentifier, $cacheName, $backendName, array $backendOptions = array()) {
73 // loading the cache backend file and class
74 list($backendFile, $backendClassReference) = explode(
76 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends'][$backendName]
79 $backendRequireFile = t3lib_div
::getFileAbsFileName($backendFile);
80 if ($backendRequireFile) {
81 t3lib_div
::requireOnce($backendRequireFile);
84 $backend = t3lib_div
::makeInstance($backendClassReference, $backendOptions);
86 if (!$backend instanceof t3lib_cache_backend_Backend
) {
87 throw new t3lib_cache_exception_InvalidCache(
88 '"' .$backendName . '" is not a valid cache backend.',
93 // loading the cache frontend file and class
94 list($cacheFile, $cacheClassReference) = explode(
96 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheFrontends'][$cacheName]
99 $cacheRequireFile = t3lib_div
::getFileAbsFileName($cacheFile);
100 if ($cacheRequireFile) {
101 t3lib_div
::requireOnce($cacheRequireFile);
104 $cache = t3lib_div
::makeInstance($cacheClassReference, $cacheIdentifier, $backend);
107 if (!$cache instanceof t3lib_cache_frontend_Frontend
) {
108 throw new t3lib_cache_exception_InvalidCache(
109 '"' .$cacheName . '" is not a valid cache.',
114 $this->cacheManager
->registerCache($cache);
122 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_factory.php']) {
123 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_factory.php']);