‪TYPO3CMS  ‪main
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\TransientBackendInterface TYPO3\CMS\Core\Cache\Backend\BackendInterface 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)
 
mixed get ($entryIdentifier)
 
bool has ($entryIdentifier)
 
bool remove ($entryIdentifier)
 
array findIdentifiersByTag ($tag)
 
 flush ()
 
 flushByTag ($tag)
 
 collectGarbage ()
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
 setDefaultLifetime ($defaultLifetime)
 
 flushByTags (array $tags)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
 flushByTags (array $tags)
 

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)
 
bool getCompression ()
 
bool setInternal ($entryIdentifier, $data, $expiration)
 
 addIdentifierToTags ($entryIdentifier, array $tags)
 
 removeIdentifierFromAllTags ($entryIdentifier)
 
array findTagsByIdentifier ($identifier)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
DateTime calculateExpiryTime ($lifetime=null)
 

Protected Attributes

Memcache Memcached $memcache
 
string $usedPeclModule = ''
 
array $servers = array( )
 
int $flags
 
string $identifierPrefix
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
FrontendInterface $cache
 
string $cacheIdentifier
 
string $context
 
int $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 Environment::getProjectPath() 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.

Definition at line 45 of file MemcachedBackend.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructs this backend

Parameters
string$context‪Unused, for backward compatibility only
array$optionsConfiguration options - depends on the actual backend
Exceptions
Exception‪if memcache is not installed

Reimplemented from TYPO3\CMS\Core\Cache\Backend\AbstractBackend.

Definition at line 92 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

Definition at line 368 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

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

Definition at line 440 of file MemcachedBackend.php.

◆ findIdentifiersByTag()

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

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

Parameters
string$tag‪The 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 328 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()

array 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$identifier‪Identifier to find tags by
Returns
‪array

Definition at line 431 of file MemcachedBackend.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

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.

Exceptions
Exception

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

Definition at line 342 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$tag‪The tag the entries must have

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

Definition at line 355 of file MemcachedBackend.php.

References TYPO3\CMS\Webhooks\Message\$identifier, and TYPO3\CMS\Core\Cache\Backend\MemcachedBackend\findIdentifiersByTag().

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

◆ get()

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

Loads data from the cache.

Parameters
string$entryIdentifier‪An 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 277 of file MemcachedBackend.php.

◆ getCompression()

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

Getter for compression flag

Returns
‪bool

Definition at line 138 of file MemcachedBackend.php.

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

◆ has()

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

Checks if a cache entry with the specified identifier exists.

Parameters
string$entryIdentifier‪An 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 296 of file MemcachedBackend.php.

◆ initializeObject()

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

Initializes the identifier prefix

Exceptions
Exception

Definition at line 148 of file MemcachedBackend.php.

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

◆ remove()

bool 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$entryIdentifier‪Specifies 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 315 of file MemcachedBackend.php.

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

◆ removeIdentifierFromAllTags()

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

◆ set()

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

Saves data in the cache.

Parameters
string$entryIdentifier‪An identifier for this specific cache entry
string$data‪The data to be stored
array$tags‪Tags to associate with this cache entry
int$lifetime‪Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
Exceptions
Exception‪if no cache frontend has been set.

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

Definition at line 215 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\Cache\Backend\MemcachedBackend\setInternal().

◆ setCache()

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

Initializes the identifier prefix when setting the cache.

Parameters
FrontendInterface$cache‪The frontend for this backend

Reimplemented from TYPO3\CMS\Core\Cache\Backend\AbstractBackend.

Definition at line 198 of file MemcachedBackend.php.

References TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cache, and TYPO3\CMS\Core\Core\Environment\getProjectPath().

◆ setCompression()

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

Setter for compression flags bit

Parameters
bool$useCompression

Definition at line 123 of file MemcachedBackend.php.

◆ setInternal()

bool TYPO3\CMS\Core\Cache\Backend\MemcachedBackend::setInternal (   $entryIdentifier,
  $data,
  $expiration 
)
protected

Stores the actual data inside memcache/memcached

Parameters
string$entryIdentifier
mixed$data
int$expiration
Returns
‪bool

Definition at line 263 of file MemcachedBackend.php.

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

◆ setPeclModule()

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

Sets the preferred PECL module

Parameters
string$peclModule
Exceptions
Exception

Definition at line 184 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$servers‪An array of servers to add.

Definition at line 113 of file MemcachedBackend.php.

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

Member Data Documentation

◆ $flags

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

Indicates whether the memcache uses compression or not (requires zlib), either 0 or \Memcached::OPT_COMPRESSION / MEMCACHE_COMPRESSED

Definition at line 77 of file MemcachedBackend.php.

◆ $identifierPrefix

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

A prefix to separate stored data from other data possibly stored in the memcache

Definition at line 83 of file MemcachedBackend.php.

◆ $memcache

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

Instance of the PHP Memcache class

Definition at line 58 of file MemcachedBackend.php.

◆ $servers

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

Array of Memcache server configurations

Definition at line 70 of file MemcachedBackend.php.

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

◆ $usedPeclModule

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

Used PECL module for memcached

Definition at line 64 of file MemcachedBackend.php.

◆ MAX_BUCKET_SIZE

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

Definition at line 52 of file MemcachedBackend.php.