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