TYPO3 CMS  TYPO3_8-7
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 
24 {
28  protected $entries = [];
29 
33  protected $tagsAndEntries = [];
34 
46  public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
47  {
48  if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
49  throw new \TYPO3\CMS\Core\Cache\Exception('No cache frontend has been set yet via setCache().', 1238244992);
50  }
51  $this->entries[$entryIdentifier] = $data;
52  foreach ($tags as $tag) {
53  $this->tagsAndEntries[$tag][$entryIdentifier] = true;
54  }
55  }
56 
64  public function get($entryIdentifier)
65  {
66  return isset($this->entries[$entryIdentifier]) ? $this->entries[$entryIdentifier] : false;
67  }
68 
76  public function has($entryIdentifier)
77  {
78  return isset($this->entries[$entryIdentifier]);
79  }
80 
88  public function remove($entryIdentifier)
89  {
90  if (isset($this->entries[$entryIdentifier])) {
91  unset($this->entries[$entryIdentifier]);
92  foreach ($this->tagsAndEntries as $tag => $_) {
93  if (isset($this->tagsAndEntries[$tag][$entryIdentifier])) {
94  unset($this->tagsAndEntries[$tag][$entryIdentifier]);
95  }
96  }
97  return true;
98  }
99  return false;
100  }
101 
110  public function findIdentifiersByTag($tag)
111  {
112  if (isset($this->tagsAndEntries[$tag])) {
113  return array_keys($this->tagsAndEntries[$tag]);
114  }
115  return [];
116  }
117 
123  public function flush()
124  {
125  $this->entries = [];
126  $this->tagsAndEntries = [];
127  }
128 
135  public function flushByTag($tag)
136  {
137  $identifiers = $this->findIdentifiersByTag($tag);
138  foreach ($identifiers as $identifier) {
139  $this->remove($identifier);
140  }
141  }
142 
148  public function collectGarbage()
149  {
150  }
151 }