TYPO3 CMS  TYPO3_6-2
TransientMemoryBackend.php
Go to the documentation of this file.
1 <?php
3 
25 
29  protected $entries = array();
30 
34  protected $tagsAndEntries = array();
35 
48  public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
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  return isset($this->entries[$entryIdentifier]) ? $this->entries[$entryIdentifier] : FALSE;
70  }
71 
79  public function has($entryIdentifier) {
80  return isset($this->entries[$entryIdentifier]);
81  }
82 
90  public function remove($entryIdentifier) {
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  if (isset($this->tagsAndEntries[$tag])) {
114  return array_keys($this->tagsAndEntries[$tag]);
115  } else {
116  return array();
117  }
118  }
119 
126  public function flush() {
127  $this->entries = array();
128  $this->tagsAndEntries = array();
129  }
130 
138  public function flushByTag($tag) {
139  $identifiers = $this->findIdentifiersByTag($tag);
140  foreach ($identifiers as $identifier) {
141  $this->remove($identifier);
142  }
143  }
144 
151  public function collectGarbage() {
152 
153  }
154 
155 }