TYPO3  7.6
TransientMemoryBackend.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Cache\Backend;
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 = array();
29 
33  protected $tagsAndEntries = array();
34 
47  public function set($entryIdentifier, $data, array $tags = array(), $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  if (!is_string($data)) {
53  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1238244993);
54  }
55  $this->entries[$entryIdentifier] = $data;
56  foreach ($tags as $tag) {
57  $this->tagsAndEntries[$tag][$entryIdentifier] = true;
58  }
59  }
60 
68  public function get($entryIdentifier)
69  {
70  return isset($this->entries[$entryIdentifier]) ? $this->entries[$entryIdentifier] : false;
71  }
72 
80  public function has($entryIdentifier)
81  {
82  return isset($this->entries[$entryIdentifier]);
83  }
84 
92  public function remove($entryIdentifier)
93  {
94  if (isset($this->entries[$entryIdentifier])) {
95  unset($this->entries[$entryIdentifier]);
96  foreach ($this->tagsAndEntries as $tag => $_) {
97  if (isset($this->tagsAndEntries[$tag][$entryIdentifier])) {
98  unset($this->tagsAndEntries[$tag][$entryIdentifier]);
99  }
100  }
101  return true;
102  } else {
103  return false;
104  }
105  }
106 
115  public function findIdentifiersByTag($tag)
116  {
117  if (isset($this->tagsAndEntries[$tag])) {
118  return array_keys($this->tagsAndEntries[$tag]);
119  } else {
120  return array();
121  }
122  }
123 
130  public function flush()
131  {
132  $this->entries = array();
133  $this->tagsAndEntries = array();
134  }
135 
143  public function flushByTag($tag)
144  {
145  $identifiers = $this->findIdentifiersByTag($tag);
146  foreach ($identifiers as $identifier) {
147  $this->remove($identifier);
148  }
149  }
150 
157  public function collectGarbage()
158  {
159  }
160 }