Commit d0ee4c6f authored by Christian Kuhn's avatar Christian Kuhn
Browse files

Fixed bug #14638: Update caching framework to its according FLOW3 revision 4443

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7828 709f56b5-9817-0410-a4d7-c38de5d9e867
parent d1977396
2010-06-07 Christian Kuhn <lolli@schwarzbu.ch>
* Fixed bug #14638: Update caching framework to its according FLOW3 revision 4443
2010-06-06 Stanislas Rolland <typo3@sjbr.ca>
 
* Follow-up to bug #14360: htmlArea RTE: Toolbar and context menu styling needs adjustments
......
......@@ -30,6 +30,7 @@
* @author Ingo Renner <ingo@typo3.org>
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_Backend {
......@@ -44,6 +45,11 @@ abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backen
*/
protected $cache;
/**
* @var string
*/
protected $cacheIdentifier;
/**
* Default lifetime of a cache entry in seconds
*
......@@ -79,12 +85,13 @@ abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backen
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
$this->cache = $cache;
$this->cacheIdentifier = $this->cache->getIdentifier();
}
/**
* Sets the default lifetime for this cache backend
*
* @param integer $defaultLifeTime Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
* @param integer $defaultLifetime Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
* @return void
* @author Karsten Dambekalns <karsten@typo3.org>
*/
......
......@@ -41,7 +41,7 @@
* Each key is prepended with a prefix. By default prefix consists from two parts
* separated by underscore character and ends in yet another underscore character:
* - "TYPO3"
* - MD5 of script path and filename and SAPI name
* - MD5 of path to TYPO3 and user running TYPO3
* This prefix makes sure that keys from the different installations do not
* conflict.
*
......@@ -49,6 +49,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_ApcBackend extends t3lib_cache_backend_AbstractBackend {
......@@ -78,6 +79,20 @@ class t3lib_cache_backend_ApcBackend extends t3lib_cache_backend_AbstractBackend
parent::__construct($options);
}
/**
* Initializes the identifier prefix when setting the cache.
*
* @param t3lib_cache_frontend_Frontend $cache The frontend for this backend
* @return void
* @author Robert Lemke <robert@typo3.org>
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
parent::setCache($cache);
$processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
$pathHash = t3lib_div::shortMD5(PATH_site . $processUser['name'], 12);
$this->identifierPrefix = 'TYPO3_' . $pathHash;
}
/**
* Saves data in the cache.
*
......@@ -107,7 +122,7 @@ class t3lib_cache_backend_ApcBackend extends t3lib_cache_backend_AbstractBackend
);
}
$tags[] = '%APCBE%' . $this->cache->getIdentifier();
$tags[] = '%APCBE%' . $this->cacheIdentifier;
$expiration = $lifetime !== NULL ? $lifetime : $this->defaultLifetime;
$success = apc_store($this->identifierPrefix . $entryIdentifier, $data, $expiration);
......@@ -241,7 +256,7 @@ class t3lib_cache_backend_ApcBackend extends t3lib_cache_backend_AbstractBackend
);
}
$this->flushByTag('%APCBE%' . $this->cache->getIdentifier());
$this->flushByTag('%APCBE%' . $this->cacheIdentifier);
}
/**
......
......@@ -28,6 +28,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBackend {
......@@ -101,7 +102,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
}
} else {
$delimiter = ':';
if ($cacheDirectory{0} != '/') {
if ($cacheDirectory[0] != '/') {
// relative path to cache directory.
$cacheDirectory = PATH_site . $cacheDirectory;
}
......@@ -114,7 +115,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
if (TYPO3_OS === 'WIN') {
$basedir = str_replace('\\', '/', $basedir);
}
if ($basedir{strlen($basedir) - 1} !== '/') {
if ($basedir[strlen($basedir) - 1] !== '/') {
$basedir .= '/';
}
if (t3lib_div::isFirstPartOfStr($cacheDirectory, $basedir)) {
......@@ -131,7 +132,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
);
}
} else {
if ($cacheDirectory{0} == '/') {
if ($cacheDirectory[0] == '/') {
// absolute path to cache directory.
$documentRoot = '/';
}
......@@ -143,7 +144,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
// after this point all paths have '/' as directory seperator
if ($cacheDirectory{strlen($cacheDirectory) - 1} !== '/') {
if ($cacheDirectory[strlen($cacheDirectory) - 1] !== '/') {
$cacheDirectory .= '/';
}
......@@ -285,7 +286,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
* Creates a tag that is associated with the given cache identifier
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string Tag to associate with this cache entry
* @param string $tag Tag to associate with this cache entry
* @return void
* @throws t3lib_cache_Exception if the tag path is not writable or exceeds the maximum allowed path length
* @author Bastian Waidelich <bastian@typo3.org>
......@@ -304,7 +305,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
}
}
$tagPathAndFilename = $absTagPath . $this->cache->getIdentifier()
$tagPathAndFilename = $absTagPath . $this->cacheIdentifier
. self::SEPARATOR . $entryIdentifier;
if (strlen($tagPathAndFilename) > $this->maximumPathLength) {
throw new t3lib_cache_Exception(
......@@ -356,7 +357,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
return FALSE;
}
if (unlink ($pathAndFilename) === FALSE) {
if (unlink($pathAndFilename) === FALSE) {
return FALSE;
}
......@@ -365,7 +366,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
return FALSE;
}
if (unlink ($pathAndFilename) === FALSE) {
if (unlink($pathAndFilename) === FALSE) {
return FALSE;
}
}
......@@ -391,7 +392,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
}
$path = $this->root . $this->cacheDirectory . 'tags/';
$pattern = $path . $tag . '/' . $this->cache->getIdentifier() . self::SEPARATOR . '*';
$pattern = $path . $tag . '/' . $this->cacheIdentifier . self::SEPARATOR . '*';
$filesFound = glob($pattern);
if ($filesFound === FALSE || count($filesFound) === 0) {
......@@ -450,7 +451,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
);
}
$dataPath = $this->root . $this->cacheDirectory . 'data/' . $this->cache->getIdentifier() . '/';
$dataPath = $this->root . $this->cacheDirectory . 'data/' . $this->cacheIdentifier . '/';
$tagsPath = $this->root . $this->cacheDirectory . 'tags/';
t3lib_div::rmdir($dataPath, true);
......@@ -515,7 +516,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
);
}
$pattern = $this->root . $this->cacheDirectory . 'data/' . $this->cache->getIdentifier() . '/*/*/*';
$pattern = $this->root . $this->cacheDirectory . 'data/' . $this->cacheIdentifier . '/*/*/*';
$filesFound = glob($pattern);
foreach ($filesFound as $cacheFilename) {
......@@ -536,7 +537,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
*/
protected function renderCacheEntryPath($identifier) {
$identifierHash = sha1($identifier);
return $this->cacheDirectory . 'data/' . $this->cache->getIdentifier() . '/' . $identifierHash[0] . '/' . $identifierHash[1] . '/';
return $this->cacheDirectory . 'data/' . $this->cacheIdentifier . '/' . $identifierHash[0] . '/' . $identifierHash[1] . '/';
}
/**
......@@ -544,7 +545,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
* Usually only one cache entry should be found - if more than one exist, this
* is due to some error or crash.
*
* @param string The cache entry identifier
* @param string $entryIdentifier The cache entry identifier
* @return mixed The file names (including path) as an array if one or more entries could be found, otherwise FALSE
* @author Robert Lemke <robert@typo3.org>
* @throws t3lib_cache_Exception if no frontend has been set
......@@ -571,7 +572,7 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
/**
* Tries to find the tag entries for the specified cache entry.
*
* @param string The cache entry identifier to find tag files for
* @param string $entryIdentifier The cache entry identifier to find tag files for
* @return array The file names (including path)
* @author Robert Lemke <robert@typo3.org>
* @throws t3lib_cache_Exception if no frontend has been set
......@@ -586,8 +587,9 @@ class t3lib_cache_backend_FileBackend extends t3lib_cache_backend_AbstractBacken
}
$path = $this->root . $this->cacheDirectory . 'tags/';
$pattern = $path . '*/' . $this->cache->getIdentifier() . self::SEPARATOR . $entryIdentifier;
return glob($pattern);
$pattern = $path . '*/' . $this->cacheIdentifier . self::SEPARATOR . $entryIdentifier;
$tagFilesFound = glob($pattern);
return ($tagFilesFound ? $tagFilesFound : array());
}
}
......
......@@ -51,6 +51,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractBackend {
......@@ -118,7 +119,6 @@ class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractB
parent::__construct($options);
$this->memcache = new Memcache();
$this->identifierPrefix = $this->getIdentifierPrefix();
$defaultPort = ini_get('memcache.default_port');
if (!count($this->servers)) {
......@@ -184,6 +184,19 @@ class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractB
}
}
/**
* Initializes the identifier prefix when setting the cache.
*
* @param t3lib_cache_frontend_Frontend $cache The frontend for this backend
* @return void
* @author Robert Lemke <robert@typo3.org>
* @author Dmitry Dulepov
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
parent::setCache($cache);
$this->identifierPrefix = 'TYPO3_' . md5(PATH_site) . '_';
}
/**
* Saves data in the cache.
*
......@@ -221,7 +234,7 @@ class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractB
);
}
$tags[] = '%MEMCACHEBE%' . $this->cache->getIdentifier();
$tags[] = '%MEMCACHEBE%' . $this->cacheIdentifier;
$expiration = $lifetime !== NULL ? $lifetime : $this->defaultLifetime;
// Memcached consideres values over 2592000 sec (30 days) as UNIX timestamp
......@@ -384,7 +397,7 @@ class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractB
throw new t3lib_cache_Exception('No cache frontend has been set via setCache() yet.', 1204111376);
}
$this->flushByTag('%MEMCACHEBE%' . $this->cache->getIdentifier());
$this->flushByTag('%MEMCACHEBE%' . $this->cacheIdentifier);
}
/**
......@@ -552,20 +565,6 @@ class t3lib_cache_backend_MemcachedBackend extends t3lib_cache_backend_AbstractB
return ($tags === FALSE ? array() : (array)$tags);
}
/**
* Returns idenfier prefix. Extensions can override this function to provide
* another identifier prefix if it is necessary for special purposes.
* Default identifier prefix is based on PATH_site only. In most cases
* it is enough because different installations use different paths and page
* IDs in the same installation never repeat.
*
* @return string Identifier prefix, ending with underscore
* @author Dmitry Dulepov
*/
protected function getIdentifierPrefix() {
return 'TYPO3_' . md5(PATH_site) . '_';
}
/**
* Does nothing, as memcached does GC itself
*
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_NullBackend extends t3lib_cache_backend_AbstractBackend {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_backend_TransientMemoryBackend extends t3lib_cache_backend_AbstractBackend {
......
......@@ -31,6 +31,7 @@
*
* @author Ingo Renner <ingo@typo3.org>
* @package TYPO3
* @api
* @subpackage t3lib
*/
interface t3lib_cache_backend_Backend {
......@@ -60,7 +61,7 @@ interface t3lib_cache_backend_Backend {
/**
* Loads data from the cache.
*
* @param string $entryIdentifier: An identifier which describes the cache entry to load
* @param string $entryIdentifier An identifier which describes the cache entry to load
* @return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
*/
public function get($entryIdentifier);
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_Exception extends Exception {
......
......@@ -32,6 +32,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_Factory implements t3lib_Singleton {
......@@ -48,7 +49,7 @@ class t3lib_cache_Factory implements t3lib_Singleton {
*
* This is called by the cache manager itself
*
* @param t3lib_cache_Manager The cache manager
* @param t3lib_cache_Manager $cacheManager The cache manager
* @return void
* @author Robert Lemke <robert@typo3.org>
* @internal
......@@ -61,10 +62,10 @@ class t3lib_cache_Factory implements t3lib_Singleton {
* Factory method which creates the specified cache along with the specified kind of backend.
* After creating the cache, it will be registered at the cache manager.
*
* @param string The name / identifier of the cache to create
* @param string Name of the cache frontend
* @param string Name of the cache backend
* @param array (optional) Array of backend options
* @param string $cacheIdentifier The name / identifier of the cache to create
* @param string $cacheName Name of the cache frontend
* @param string $backendName Name of the cache backend
* @param array $backendOptions (optional) Array of backend options
* @return t3lib_cache_frontend_Frontend The created cache frontend
* @author Robert Lemke <robert@typo3.org>
*/
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_Manager implements t3lib_Singleton {
......@@ -114,7 +115,7 @@ class t3lib_cache_Manager implements t3lib_Singleton {
$backend = isset($configuration['backend']) ? $configuration['backend'] : $this->cacheConfigurations['default']['backend'];
$backendOptions = isset($configuration['backendOptions']) ? $configuration['backendOptions'] : $this->cacheConfigurations['default']['backendOptions'];
$cache = $this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions);
$this->cacheFactory->create($identifier, $frontend, $backend, $backendOptions);
}
}
}
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_ClassAlreadyLoaded extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_DuplicateIdentifier extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_InvalidBackend extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_InvalidCache extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_InvalidData extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_exception_NoSuchCache extends t3lib_cache_Exception {
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
abstract class t3lib_cache_frontend_AbstractFrontend implements t3lib_cache_frontend_Frontend {
......@@ -190,7 +191,7 @@ abstract class t3lib_cache_frontend_AbstractFrontend implements t3lib_cache_fron
/**
* Checks the validity of an entry identifier. Returns true if it's valid.
*
* @param string An identifier to be checked for validity
* @param string $identifier An identifier to be checked for validity
* @return boolean
* @author Christian Jul Jensen <julle@typo3.org>
*/
......@@ -201,7 +202,7 @@ abstract class t3lib_cache_frontend_AbstractFrontend implements t3lib_cache_fron
/**
* Checks the validity of a tag. Returns true if it's valid.
*
* @param string An identifier to be checked for validity
* @param string $tag An identifier to be checked for validity
* @return boolean
* @author Robert Lemke <robert@typo3.org>
*/
......
......@@ -30,6 +30,7 @@
*
* @package TYPO3
* @subpackage t3lib_cache
* @api
* @version $Id$
*/
class t3lib_cache_frontend_StringFrontend extends t3lib_cache_frontend_AbstractFrontend {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment