2 namespace TYPO3\CMS\Core\Cache\Backend;
57 if (!extension_loaded(
'xcache')) {
59 'The PHP extension "xcache" must be installed and loaded in order to use the xcache backend.',
63 parent::__construct(
$context, $options);
77 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null)
82 if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
84 'No cache frontend has been set yet via setCache().',
88 if (!is_string($data)) {
89 throw new Exception\InvalidDataException(
90 'The specified data is of type "' . gettype($data) .
'" but a string is expected.',
94 $tags[] =
'%XCBE%' . $this->cache->getIdentifier();
96 $success = xcache_set($this->identifierPrefix . $entryIdentifier, $data, $expiration);
97 if ($success ===
true) {
102 'Could not set value.',
114 public function get($entryIdentifier)
119 $value = xcache_get($this->identifierPrefix . $entryIdentifier);
120 return $value ?:
false;
129 public function has($entryIdentifier)
134 return xcache_isset($this->identifierPrefix . $entryIdentifier);
145 public function remove($entryIdentifier)
151 return xcache_unset($this->identifierPrefix . $entryIdentifier);
166 $identifiers = xcache_get($this->identifierPrefix .
'tag_' . $tag);
167 return $identifiers ?: array();
182 $tags = xcache_get($this->identifierPrefix .
'ident_' . $identifier);
183 return $tags ?: array();
197 if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
199 'Yet no cache frontend has been set via setCache().',
203 $this->
flushByTag(
'%XCBE%' . $this->cache->getIdentifier());
216 foreach ($identifiers as $identifier) {
217 $this->
remove($identifier);
236 $existingTagsUpdated =
false;
239 foreach ($tags as $tag) {
242 if (!in_array($entryIdentifier, $identifiers,
true)) {
243 $identifiers[] = $entryIdentifier;
244 xcache_set($this->identifierPrefix .
'tag_' . $tag, $identifiers);
247 if (!in_array($tag, $existingTags,
true)) {
248 $existingTags[] = $tag;
249 $existingTagsUpdated =
true;
254 if ($existingTagsUpdated) {
255 xcache_set($this->identifierPrefix .
'ident_' . $entryIdentifier, $existingTags);
273 foreach ($tags as $tag) {
280 if (($key = array_search($entryIdentifier, $identifiers)) !==
false) {
281 unset($identifiers[$key]);
282 if (!empty($identifiers)) {
283 xcache_set($this->identifierPrefix .
'tag_' . $tag, $identifiers);
285 xcache_unset($this->identifierPrefix .
'tag_' . $tag);
290 xcache_unset($this->identifierPrefix .
'ident_' . $entryIdentifier);
311 $varSize = ini_get(
'xcache.var_size');
312 return php_sapi_name() ===
'cli' || empty($varSize);