‪TYPO3CMS  10.4
AbstractBackend.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 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
23 
27 abstract class ‪AbstractBackend implements ‪BackendInterface, LoggerAwareInterface
28 {
29  use LoggerAwareTrait;
30 
31  const ‪DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000';
38  protected ‪$cache;
39 
43  protected ‪$cacheIdentifier;
44 
53  protected ‪$context;
54 
60  protected ‪$defaultLifetime = 3600;
61 
69  public function ‪__construct(‪$context, array $options = [])
70  {
71  $this->context = ‪$context;
72  foreach ($options as $optionKey => $optionValue) {
73  $methodName = 'set' . ucfirst($optionKey);
74  if (method_exists($this, $methodName)) {
75  $this->{$methodName}($optionValue);
76  } else {
77  throw new \InvalidArgumentException('Invalid cache backend option "' . $optionKey . '" for backend of type "' . static::class . '"', 1231267498);
78  }
79  }
80  if ($this->logger === null) {
81  $this->setLogger(
82  GeneralUtility::makeInstance(LogManager::class)
83  ->getLogger(static::class)
84  );
85  }
86  }
87 
94  {
95  $this->cache = ‪$cache;
96  $this->cacheIdentifier = $this->cache->‪getIdentifier();
97  }
98 
106  {
107  if (!is_int(‪$defaultLifetime) || ‪$defaultLifetime < 0) {
108  throw new \InvalidArgumentException('The default lifetime must be given as a positive integer.', 1233072774);
109  }
110  $this->defaultLifetime = ‪$defaultLifetime;
111  }
112 
123  public function ‪flushByTags(array $tags)
124  {
125  // todo: flushByTag is not necessarily implemented since it's neither defined of the interface, nor defined in
126  // this class as abstract method. Therefore this potentially triggers a fatal error during runtime.
127  array_walk($tags, [$this, 'flushByTag']);
128  }
129 
137  protected function ‪calculateExpiryTime($lifetime = null)
138  {
139  if ($lifetime === self::UNLIMITED_LIFETIME || $lifetime === null && $this->defaultLifetime === self::UNLIMITED_LIFETIME) {
140  $expiryTime = new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new \DateTimeZone('UTC'));
141  } else {
142  if ($lifetime === null) {
143  $lifetime = ‪$this->defaultLifetime;
144  }
145  $expiryTime = new \DateTime('now +' . $lifetime . ' seconds', new \DateTimeZone('UTC'));
146  }
147  return $expiryTime;
148  }
149 }
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\calculateExpiryTime
‪DateTime calculateExpiryTime($lifetime=null)
Definition: AbstractBackend.php:133
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setCache
‪setCache(FrontendInterface $cache)
Definition: AbstractBackend.php:89
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\UNLIMITED_LIFETIME
‪const UNLIMITED_LIFETIME
Definition: AbstractBackend.php:32
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\__construct
‪__construct($context, array $options=[])
Definition: AbstractBackend.php:65
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$defaultLifetime
‪int $defaultLifetime
Definition: AbstractBackend.php:56
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractBackend.php:119
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:25
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cache
Definition: AbstractBackend.php:37
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setDefaultLifetime
‪setDefaultLifetime($defaultLifetime)
Definition: AbstractBackend.php:101
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\DATETIME_EXPIRYTIME_UNLIMITED
‪const DATETIME_EXPIRYTIME_UNLIMITED
Definition: AbstractBackend.php:31
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cacheIdentifier
‪string $cacheIdentifier
Definition: AbstractBackend.php:41
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:30
‪TYPO3\CMS\Core\Cache\Backend
Definition: AbstractBackend.php:16
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$context
‪string $context
Definition: AbstractBackend.php:50
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46