‪TYPO3CMS  ‪main
AbstractFrontend.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
24 abstract class ‪AbstractFrontend implements ‪FrontendInterface
25 {
31  protected ‪$identifier;
32 
36  protected ‪$backend;
37 
46  {
47  if (preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) !== 1) {
48  throw new \InvalidArgumentException('"' . ‪$identifier . '" is not a valid cache identifier.', 1203584729);
49  }
50  $this->identifier = ‪$identifier;
51  $this->backend = ‪$backend;
52  $this->backend->‪setCache($this);
53  }
54 
60  public function ‪getIdentifier()
61  {
62  return ‪$this->identifier;
63  }
64 
70  public function ‪getBackend()
71  {
72  return ‪$this->backend;
73  }
74 
82  public function ‪has($entryIdentifier)
83  {
84  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
85  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058486);
86  }
87  return $this->backend->has($entryIdentifier);
88  }
89 
97  public function remove($entryIdentifier)
98  {
99  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
100  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058495);
101  }
102  return $this->backend->remove($entryIdentifier);
103  }
104 
108  public function ‪flush()
109  {
110  $this->backend->flush();
111  }
112 
119  public function ‪flushByTags(array $tags)
120  {
121  foreach ($tags as $tag) {
122  if (!$this->‪isValidTag($tag)) {
123  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
124  }
125  }
126  if ($this->backend instanceof ‪TaggableBackendInterface) {
127  $this->backend->flushByTags($tags);
128  }
129  }
130 
137  public function ‪flushByTag($tag)
138  {
139  if (!$this->‪isValidTag($tag)) {
140  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
141  }
142 
143  if ($this->backend instanceof ‪TaggableBackendInterface) {
144  $this->backend->flushByTag($tag);
145  }
146  }
147 
151  public function ‪collectGarbage()
152  {
153  $this->backend->collectGarbage();
154  }
155 
163  {
164  return preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) === 1;
165  }
166 
173  public function ‪isValidTag($tag)
174  {
175  if (!is_array($tag)) {
176  return preg_match(self::PATTERN_TAG, $tag) === 1;
177  }
178  foreach ($tag as $tagValue) {
179  if (!$this->‪isValidTag($tagValue)) {
180  return false;
181  }
182  }
183  return true;
184  }
185 }
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface\setCache
‪setCache(FrontendInterface $cache)
‪TYPO3\CMS\Core\Cache\Frontend
Definition: AbstractFrontend.php:16
‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
Definition: TaggableBackendInterface.php:22
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\has
‪bool has($entryIdentifier)
Definition: AbstractFrontend.php:80
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:25
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getIdentifier
‪string getIdentifier()
Definition: AbstractFrontend.php:58
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$identifier
‪string $identifier
Definition: AbstractFrontend.php:30
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:160
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\__construct
‪__construct($identifier, BackendInterface $backend)
Definition: AbstractFrontend.php:43
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractFrontend.php:117
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTag
‪flushByTag($tag)
Definition: AbstractFrontend.php:135
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:171
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$backend
‪BackendInterface TaggableBackendInterface $backend
Definition: AbstractFrontend.php:34
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\collectGarbage
‪collectGarbage()
Definition: AbstractFrontend.php:149
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getBackend
‪BackendInterface getBackend()
Definition: AbstractFrontend.php:68
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flush
‪flush()
Definition: AbstractFrontend.php:106
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:25