[TASK] Use BE_USER->isAdmin()
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Object / Container / ClassInfoCache.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Object\Container;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Simple Cache for classInfos
19 */
20 class ClassInfoCache
21 {
22 /**
23 * @var array
24 */
25 private $level1Cache = [];
26
27 /**
28 * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
29 */
30 private $level2Cache;
31
32 /**
33 * constructor
34 */
35 public function __construct()
36 {
37 $this->initializeLevel2Cache();
38 }
39
40 /**
41 * checks if cacheentry exists for id
42 *
43 * @param string $id
44 * @return bool
45 */
46 public function has($id)
47 {
48 return isset($this->level1Cache[$id]) || $this->level2Cache->has($id);
49 }
50
51 /**
52 * Gets the cache for the id
53 *
54 * @param string $id
55 * @return mixed
56 */
57 public function get($id)
58 {
59 if (!isset($this->level1Cache[$id])) {
60 $this->level1Cache[$id] = $this->level2Cache->get($id);
61 }
62 return $this->level1Cache[$id];
63 }
64
65 /**
66 * sets the cache for the id
67 *
68 * @param string $id
69 * @param mixed $value
70 */
71 public function set($id, $value)
72 {
73 $this->level1Cache[$id] = $value;
74 $this->level2Cache->set($id, $value);
75 }
76
77 /**
78 * Initialize the TYPO3 second level cache
79 */
80 private function initializeLevel2Cache()
81 {
82 $this->level2Cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('extbase_object');
83 }
84 }