‪TYPO3CMS  ‪main
TransientMemoryBackend.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
29  protected ‪$entries = [];
30 
34  protected ‪$tagsAndEntries = [];
35 
45  public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
46  {
47  if (!$this->cache instanceof ‪FrontendInterface) {
48  throw new ‪Exception('No cache frontend has been set yet via setCache().', 1238244992);
49  }
50  $this->entries[$entryIdentifier] = $data;
51  foreach ($tags as $tag) {
52  $this->tagsAndEntries[$tag][$entryIdentifier] = true;
53  }
54  }
55 
62  public function get($entryIdentifier)
63  {
64  return $this->entries[$entryIdentifier] ?? false;
65  }
66 
73  public function ‪has($entryIdentifier)
74  {
75  return isset($this->entries[$entryIdentifier]);
76  }
77 
84  public function remove($entryIdentifier)
85  {
86  if (isset($this->entries[$entryIdentifier])) {
87  unset($this->entries[$entryIdentifier]);
88  foreach ($this->tagsAndEntries as $tag => $_) {
89  if (isset($this->tagsAndEntries[$tag][$entryIdentifier])) {
90  unset($this->tagsAndEntries[$tag][$entryIdentifier]);
91  }
92  }
93  return true;
94  }
95  return false;
96  }
97 
105  public function ‪findIdentifiersByTag($tag)
106  {
107  if (isset($this->tagsAndEntries[$tag])) {
108  return array_keys($this->tagsAndEntries[$tag]);
109  }
110  return [];
111  }
112 
116  public function ‪flush()
117  {
118  $this->entries = [];
119  $this->tagsAndEntries = [];
120  }
121 
127  public function ‪flushByTag($tag)
128  {
129  $identifiers = $this->‪findIdentifiersByTag($tag);
130  foreach ($identifiers as ‪$identifier) {
131  $this->remove(‪$identifier);
132  }
133  }
134 
138  public function ‪collectGarbage() {}
139 }
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend
Definition: TransientMemoryBackend.php:25
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\flush
‪flush()
Definition: TransientMemoryBackend.php:114
‪TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface
Definition: TransientBackendInterface.php:32
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\flushByTag
‪flushByTag($tag)
Definition: TransientMemoryBackend.php:125
‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
Definition: TaggableBackendInterface.php:22
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\$entries
‪array $entries
Definition: TransientMemoryBackend.php:28
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\findIdentifiersByTag
‪array findIdentifiersByTag($tag)
Definition: TransientMemoryBackend.php:103
‪TYPO3\CMS\Core\Cache\Exception
Definition: DuplicateIdentifierException.php:16
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\collectGarbage
‪collectGarbage()
Definition: TransientMemoryBackend.php:136
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\$tagsAndEntries
‪array $tagsAndEntries
Definition: TransientMemoryBackend.php:32
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪TYPO3\CMS\Core\Cache\Backend
Definition: AbstractBackend.php:16
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend\has
‪bool has($entryIdentifier)
Definition: TransientMemoryBackend.php:71
‪TYPO3\CMS\Core\Cache\Exception
Definition: Exception.php:21