TYPO3 CMS  TYPO3_7-6
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 
47  public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
48  {
49  if (!$this->cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
50  throw new \TYPO3\CMS\Core\Cache\Exception('No cache frontend has been set yet via setCache().', 1238244992);
51  }
52  $this->entries[$entryIdentifier] = $data;
53  foreach ($tags as $tag) {
54  $this->tagsAndEntries[$tag][$entryIdentifier] = true;
55  }
56  }
57 
65  public function get($entryIdentifier)
66  {
67  return isset($this->entries[$entryIdentifier]) ? $this->entries[$entryIdentifier] : false;
68  }
69 
77  public function has($entryIdentifier)
78  {
79  return isset($this->entries[$entryIdentifier]);
80  }
81 
89  public function remove($entryIdentifier)
90  {
91  if (isset($this->entries[$entryIdentifier])) {
92  unset($this->entries[$entryIdentifier]);
93  foreach ($this->tagsAndEntries as $tag => $_) {
94  if (isset($this->tagsAndEntries[$tag][$entryIdentifier])) {
95  unset($this->tagsAndEntries[$tag][$entryIdentifier]);
96  }
97  }
98  return true;
99  } else {
100  return false;
101  }
102  }
103 
112  public function findIdentifiersByTag($tag)
113  {
114  if (isset($this->tagsAndEntries[$tag])) {
115  return array_keys($this->tagsAndEntries[$tag]);
116  } else {
117  return [];
118  }
119  }
120 
127  public function flush()
128  {
129  $this->entries = [];
130  $this->tagsAndEntries = [];
131  }
132 
140  public function flushByTag($tag)
141  {
142  $identifiers = $this->findIdentifiersByTag($tag);
143  foreach ($identifiers as $identifier) {
144  $this->remove($identifier);
145  }
146  }
147 
154  public function collectGarbage()
155  {
156  }
157 }