TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Cache\Backend\MemcachedBackend Class Reference
Inheritance diagram for TYPO3\CMS\Core\Cache\Backend\MemcachedBackend:
TYPO3\CMS\Core\Cache\Backend\AbstractBackend TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface TYPO3\CMS\Core\Cache\Backend\BackendInterface TYPO3\CMS\Core\Cache\Backend\BackendInterface

Public Member Functions

 __construct ($context, array $options=[])
 
 initializeObject ()
 
 setPeclModule ($peclModule)
 
 setCache (FrontendInterface $cache)
 
 set ($entryIdentifier, $data, array $tags=[], $lifetime=null)
 
 get ($entryIdentifier)
 
 has ($entryIdentifier)
 
 remove ($entryIdentifier)
 
 findIdentifiersByTag ($tag)
 
 flush ()
 
 flushByTag ($tag)
 
 collectGarbage ()
 
- Public Member Functions inherited from TYPO3\CMS\Core\Cache\Backend\AbstractBackend
 __construct ($context, array $options=[])
 
 setCache (\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
 
 setDefaultLifetime ($defaultLifetime)
 

Public Attributes

const MAX_BUCKET_SIZE = 1048534
 
- Public Attributes inherited from TYPO3\CMS\Core\Cache\Backend\AbstractBackend
const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'
 
const UNLIMITED_LIFETIME = 0
 

Protected Member Functions

 setServers (array $servers)
 
 setCompression ($useCompression)
 
 getCompression ()
 
 addIdentifierToTags ($entryIdentifier, array $tags)
 
 removeIdentifierFromAllTags ($entryIdentifier)
 
 findTagsByIdentifier ($identifier)
 
- Protected Member Functions inherited from TYPO3\CMS\Core\Cache\Backend\AbstractBackend
 calculateExpiryTime ($lifetime=null)
 

Protected Attributes

 $memcache
 
 $usedPeclModule = ''
 
 $servers = []
 
 $flags
 
 $identifierPrefix
 
- Protected Attributes inherited from TYPO3\CMS\Core\Cache\Backend\AbstractBackend
 $cache
 
 $cacheIdentifier
 
 $context
 
 $defaultLifetime = 3600
 

Detailed Description

A caching backend which stores cache entries by using Memcached.

This backend uses the following types of Memcache keys:

  • tag_xxx xxx is tag name, value is array of associated identifiers identifier. This is "forward" tag index. It is mainly used for obtaining content by tag (get identifier by tag -> get content by identifier)
  • ident_xxx xxx is identifier, value is array of associated tags. This is "reverse" tag index. It provides quick access for all tags associated with this identifier and used when removing the identifier

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"
  • Current site path obtained from the PATH_site constant This prefix makes sure that keys from the different installations do not conflict.

Note: When using the Memcached backend to store values of more than ~1 MB, the data will be split into chunks to make them fit into the memcached limits.

This file is a backport from FLOW3 by Ingo Renner.

Definition at line 47 of file MemcachedBackend.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::__construct (   $context,
array  $options = [] 
)

Constructs this backend

Parameters
string$contextFLOW3's application context
array$optionsConfiguration options - depends on the actual backend
Exceptions
Exceptionif memcache is not installed

Definition at line 99 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$context.

Member Function Documentation

◆ addIdentifierToTags()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::addIdentifierToTags (   $entryIdentifier,
array  $tags 
)
protected

Associates the identifier with the given tags

Parameters
string$entryIdentifier
array$tags
Returns
void

Definition at line 398 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findIdentifiersByTag(), and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findTagsByIdentifier().

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\set().

◆ collectGarbage()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::collectGarbage ( )

Does nothing, as memcached does GC itself

Returns
void

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 475 of file MemcachedBackend.php.

◆ findIdentifiersByTag()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::findIdentifiersByTag (   $tag)

Finds and returns all cache entry identifiers which are tagged by the specified tag.

Parameters
string$tagThe tag to search for
Returns
array An array of entries with all matching entries. An empty array if no entries matched

Implements TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface.

Definition at line 351 of file MemcachedBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\addIdentifierToTags(), TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\flushByTag(), and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\removeIdentifierFromAllTags().

◆ findTagsByIdentifier()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::findTagsByIdentifier (   $identifier)
protected

Finds all tags for the given identifier. This function uses reverse tag index to search for tags.

Parameters
string$identifierIdentifier to find tags by
Returns
array

Definition at line 463 of file MemcachedBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\addIdentifierToTags(), and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\removeIdentifierFromAllTags().

◆ flush()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::flush ( )

Removes all cache entries of this cache.

Returns
void
Exceptions
Exception

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 368 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\flushByTag().

◆ flushByTag()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::flushByTag (   $tag)

Removes all cache entries of this cache which are tagged by the specified tag.

Parameters
string$tagThe tag the entries must have
Returns
void

Implements TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface.

Definition at line 383 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findIdentifiersByTag().

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\flush().

◆ get()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::get (   $entryIdentifier)

Loads data from the cache.

Parameters
string$entryIdentifierAn identifier which describes the cache entry to load
Returns
mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 297 of file MemcachedBackend.php.

◆ getCompression()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::getCompression ( )
protected

Getter for compression flag

Returns
bool

Definition at line 152 of file MemcachedBackend.php.

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\initializeObject().

◆ has()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::has (   $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

Parameters
string$entryIdentifierAn identifier specifying the cache entry
Returns
bool TRUE if such an entry exists, FALSE if not

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 317 of file MemcachedBackend.php.

◆ initializeObject()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::initializeObject ( )

Initializes the identifier prefix

Returns
void
Exceptions
Exception

Definition at line 163 of file MemcachedBackend.php.

References $host, and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\getCompression().

◆ remove()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::remove (   $entryIdentifier)

Removes all cache entries matching the specified identifier. Usually this only affects one entry but if - for what reason ever - old entries for the identifier still exist, they are removed as well.

Parameters
string$entryIdentifierSpecifies the cache entry to remove
Returns
bool TRUE if (at least) an entry could be removed or FALSE if no entry was found

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 337 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\removeIdentifierFromAllTags().

◆ removeIdentifierFromAllTags()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::removeIdentifierFromAllTags (   $entryIdentifier)
protected

Removes association of the identifier with the given tags

Parameters
string$entryIdentifier
Returns
void

Definition at line 430 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findIdentifiersByTag(), and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findTagsByIdentifier().

Referenced by TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\remove(), and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\set().

◆ set()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::set (   $entryIdentifier,
  $data,
array  $tags = [],
  $lifetime = null 
)

Saves data in the cache.

Parameters
string$entryIdentifierAn identifier for this specific cache entry
string$dataThe data to be stored
array$tagsTags to associate with this cache entry
int$lifetimeLifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
Returns
void
Exceptions
Exceptionif no cache frontend has been set.

Implements TYPO3\CMS\Core\Cache\Backend\BackendInterface.

Definition at line 234 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cacheIdentifier, TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$defaultLifetime, $GLOBALS, TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\addIdentifierToTags(), TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\removeIdentifierFromAllTags(), and TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_WARNING.

◆ setCache()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::setCache ( FrontendInterface  $cache)

Initializes the identifier prefix when setting the cache.

Parameters
FrontendInterface$cacheThe frontend for this backend
Returns
void

Definition at line 214 of file MemcachedBackend.php.

◆ setCompression()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::setCompression (   $useCompression)
protected

Setter for compression flags bit

Parameters
bool$useCompression
Returns
void

Definition at line 136 of file MemcachedBackend.php.

◆ setPeclModule()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::setPeclModule (   $peclModule)

Sets the preferred PECL module

Parameters
string$peclModule
Exceptions
Exception

Definition at line 199 of file MemcachedBackend.php.

◆ setServers()

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::setServers ( array  $servers)
protected

Setter for servers to be used. Expects an array, the values are expected to be formatted like "<host>[:<port>]" or "unix://<path>"

Parameters
array$serversAn array of servers to add.
Returns
void

Definition at line 124 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\$servers.

Member Data Documentation

◆ $flags

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::$flags
protected

Definition at line 83 of file MemcachedBackend.php.

◆ $identifierPrefix

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::$identifierPrefix
protected

Definition at line 90 of file MemcachedBackend.php.

◆ $memcache

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::$memcache
protected

Definition at line 61 of file MemcachedBackend.php.

◆ $servers

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::$servers = []
protected

◆ $usedPeclModule

TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::$usedPeclModule = ''
protected

Definition at line 68 of file MemcachedBackend.php.

◆ MAX_BUCKET_SIZE

const TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::MAX_BUCKET_SIZE = 1048534

Definition at line 54 of file MemcachedBackend.php.