92 if (!extension_loaded(
'memcache')) {
93 throw new \TYPO3\CMS\Core\Cache\Exception(
'The PHP extension "memcache" must be installed and loaded in ' .
'order to use the Memcached backend.', 1213987706);
95 parent::__construct(
$context, $options);
118 if ($useCompression === TRUE) {
119 $this->flags ^= MEMCACHE_COMPRESSED;
121 $this->flags &= ~MEMCACHE_COMPRESSED;
132 if (!count($this->servers)) {
133 throw new \TYPO3\CMS\Core\Cache\Exception(
'No servers were given to Memcache', 1213115903);
135 $this->memcache = new \Memcache();
136 $defaultPort = ini_get(
'memcache.default_port');
137 foreach ($this->servers as $server) {
138 if (substr($server, 0, 7) ==
'unix://') {
142 if (substr($server, 0, 6) ===
'tcp://') {
143 $server = substr($server, 6);
145 if (strpos($server,
':') !== FALSE) {
146 list(
$host, $port) = explode(
':', $server, 2);
149 $port = $defaultPort;
152 $this->memcache->addserver(
$host, $port);
163 parent::setCache($cache);
164 $identifierHash = substr(md5(PATH_site . $this->context . $this->cacheIdentifier), 0, 12);
165 $this->identifierPrefix =
'TYPO3_' . $identifierHash .
'_';
181 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
182 if (strlen($this->identifierPrefix . $entryIdentifier) > 250) {
183 throw new \InvalidArgumentException(
'Could not set value. Key more than 250 characters (' . $this->identifierPrefix . $entryIdentifier .
').', 1232969508);
185 if (!$this->cache instanceof \
TYPO3\CMS\Core\
Cache\Frontend\FrontendInterface) {
186 throw new \TYPO3\CMS\Core\Cache\Exception(
'No cache frontend has been set yet via setCache().', 1207149215);
188 if (!is_string($data)) {
189 throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException(
'The specified data is of type "' . gettype($data) .
'" but a string is expected.', 1207149231);
195 if ($expiration > 2592000) {
196 $expiration +=
$GLOBALS[
'EXEC_TIME'];
199 if (strlen($data) > self::MAX_BUCKET_SIZE) {
200 $data = str_split($data, 1024 * 1000);
203 foreach ($data as $chunk) {
204 $success = $success && $this->memcache->set($this->identifierPrefix . $entryIdentifier .
'_chunk_' . $chunkNumber, $chunk, $this->flags, $expiration);
207 $success = $success && $this->memcache->set($this->identifierPrefix . $entryIdentifier,
'TYPO3*chunked:' . $chunkNumber, $this->flags, $expiration);
209 $success = $this->memcache->set($this->identifierPrefix . $entryIdentifier, $data, $this->flags, $expiration);
211 if ($success === TRUE) {
215 throw new \TYPO3\CMS\Core\Cache\Exception(
'Could not set data to memcache server.', 1275830266);
229 public function get($entryIdentifier) {
230 $value = $this->memcache->get($this->identifierPrefix . $entryIdentifier);
231 if (substr($value, 0, 14) ===
'TYPO3*chunked:') {
232 list(, $chunkCount) = explode(
':', $value);
234 for ($chunkNumber = 1; $chunkNumber < $chunkCount; $chunkNumber++) {
235 $value .= $this->memcache->get($this->identifierPrefix . $entryIdentifier .
'_chunk_' . $chunkNumber);
248 public function has($entryIdentifier) {
249 return $this->memcache->get($this->identifierPrefix . $entryIdentifier) !== FALSE;
261 public function remove($entryIdentifier) {
263 return $this->memcache->delete($this->identifierPrefix . $entryIdentifier, 0);
275 $identifiers = $this->memcache->get($this->identifierPrefix .
'tag_' . $tag);
276 if ($identifiers !== FALSE) {
277 return (array) $identifiers;
291 if (!$this->cache instanceof \
TYPO3\CMS\Core\
Cache\Frontend\FrontendInterface) {
292 throw new \TYPO3\CMS\Core\Cache\Exception(
'No cache frontend has been set via setCache() yet.', 1204111376);
294 $this->
flushByTag(
'%MEMCACHEBE%' . $this->cacheIdentifier);
306 foreach ($identifiers as $identifier) {
307 $this->
remove($identifier);
321 $existingTagsUpdated = FALSE;
323 foreach ($tags as $tag) {
326 if (!in_array($entryIdentifier, $identifiers, TRUE)) {
327 $identifiers[] = $entryIdentifier;
328 $this->memcache->set($this->identifierPrefix .
'tag_' . $tag, $identifiers);
331 if (!in_array($tag, $existingTags, TRUE)) {
332 $existingTags[] = $tag;
333 $existingTagsUpdated = TRUE;
338 if ($existingTagsUpdated) {
339 $this->memcache->set($this->identifierPrefix .
'ident_' . $entryIdentifier, $existingTags);
354 foreach ($tags as $tag) {
361 if (($key = array_search($entryIdentifier, $identifiers)) !== FALSE) {
362 unset($identifiers[$key]);
363 if (count($identifiers)) {
364 $this->memcache->set($this->identifierPrefix .
'tag_' . $tag, $identifiers);
366 $this->memcache->delete($this->identifierPrefix .
'tag_' . $tag, 0);
371 $this->memcache->delete($this->identifierPrefix .
'ident_' . $entryIdentifier, 0);
383 $tags = $this->memcache->get($this->identifierPrefix .
'ident_' . $identifier);
384 return $tags === FALSE ? array() : (array) $tags;
setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
__construct($context, array $options=array())
findTagsByIdentifier($identifier)
const SYSLOG_SEVERITY_WARNING
addIdentifierToTags($entryIdentifier, array $tags)
setCompression($useCompression)
setServers(array $servers)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
findIdentifiersByTag($tag)
removeIdentifierFromAllTags($entryIdentifier)