‪TYPO3CMS  11.5
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 
21 
25 abstract class ‪AbstractFrontend implements ‪FrontendInterface
26 {
32  protected ‪$identifier;
33 
37  protected ‪$backend;
38 
47  {
48  if (preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) !== 1) {
49  throw new \InvalidArgumentException('"' . ‪$identifier . '" is not a valid cache identifier.', 1203584729);
50  }
51  if (strpos(‪$identifier, 'cache_') === 0) {
52  trigger_error('Setting up a cache as in "' . ‪$identifier . '" with the "cache_" prefix is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
53  ‪$identifier = substr(‪$identifier, 6);
54  }
55  $this->identifier = ‪$identifier;
56  $this->backend = ‪$backend;
57  $this->backend->‪setCache($this);
58  }
59 
65  public function ‪getIdentifier()
66  {
67  return ‪$this->identifier;
68  }
69 
75  public function ‪getBackend()
76  {
77  return ‪$this->backend;
78  }
79 
87  public function ‪has($entryIdentifier)
88  {
89  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
90  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058486);
91  }
92  return $this->backend->has($entryIdentifier);
93  }
94 
102  public function remove($entryIdentifier)
103  {
104  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
105  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058495);
106  }
107  return $this->backend->remove($entryIdentifier);
108  }
109 
113  public function ‪flush()
114  {
115  $this->backend->flush();
116  }
117 
124  public function ‪flushByTags(array $tags)
125  {
126  foreach ($tags as $tag) {
127  if (!$this->‪isValidTag($tag)) {
128  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
129  }
130  }
131  if ($this->backend instanceof ‪TaggableBackendInterface) {
132  $this->backend->flushByTags($tags);
133  }
134  }
135 
142  public function ‪flushByTag($tag)
143  {
144  if (!$this->‪isValidTag($tag)) {
145  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
146  }
147 
148  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'] ?? [] as $_funcRef) {
149  $params = ['tag' => $tag];
150  GeneralUtility::callUserFunction($_funcRef, $params, $this);
151  }
152 
153  if ($this->backend instanceof ‪TaggableBackendInterface) {
154  $this->backend->flushByTag($tag);
155  }
156  }
157 
161  public function ‪collectGarbage()
162  {
163  $this->backend->collectGarbage();
164  }
165 
173  {
174  return preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) === 1;
175  }
176 
183  public function ‪isValidTag($tag)
184  {
185  if (!is_array($tag)) {
186  return preg_match(self::PATTERN_TAG, $tag) === 1;
187  }
188  foreach ($tag as $tagValue) {
189  if (!$this->‪isValidTag($tagValue)) {
190  return false;
191  }
192  }
193  return true;
194  }
195 }
‪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:85
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:25
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getIdentifier
‪string getIdentifier()
Definition: AbstractFrontend.php:63
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$identifier
‪string $identifier
Definition: AbstractFrontend.php:31
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:170
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\__construct
‪__construct($identifier, BackendInterface $backend)
Definition: AbstractFrontend.php:44
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractFrontend.php:122
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTag
‪flushByTag($tag)
Definition: AbstractFrontend.php:140
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:181
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$backend
‪BackendInterface TaggableBackendInterface $backend
Definition: AbstractFrontend.php:35
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\collectGarbage
‪collectGarbage()
Definition: AbstractFrontend.php:159
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getBackend
‪BackendInterface getBackend()
Definition: AbstractFrontend.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flush
‪flush()
Definition: AbstractFrontend.php:111
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:26