‪TYPO3CMS  10.4
VariableFrontend.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 
25 {
36  public function set($entryIdentifier, $variable, array $tags = [], $lifetime = null)
37  {
38  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
39  throw new \InvalidArgumentException(
40  '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
41  1233058264
42  );
43  }
44  foreach ($tags as $tag) {
45  if (!$this->‪isValidTag($tag)) {
46  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058269);
47  }
48  }
49 
50  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'] ?? [] as $_funcRef) {
51  $params = [
52  'entryIdentifier' => &$entryIdentifier,
53  'variable' => &$variable,
54  'tags' => &$tags,
55  'lifetime' => &$lifetime
56  ];
57  GeneralUtility::callUserFunction($_funcRef, $params, $this);
58  }
59  if (!$this->backend instanceof ‪TransientBackendInterface) {
60  $variable = serialize($variable);
61  }
62  $this->backend->set($entryIdentifier, $variable, $tags, $lifetime);
63  }
64 
73  public function get($entryIdentifier)
74  {
75  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
76  throw new \InvalidArgumentException(
77  '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
78  1233058294
79  );
80  }
81  $rawResult = $this->backend->get($entryIdentifier);
82  if ($rawResult === false) {
83  return false;
84  }
85  return $this->backend instanceof ‪TransientBackendInterface ? $rawResult : unserialize($rawResult);
86  }
87 }
‪TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface
Definition: TransientBackendInterface.php:33
‪TYPO3\CMS\Core\Cache\Frontend
Definition: AbstractFrontend.php:16
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:171
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:182
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:27