1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cache.php
См. документацию.
1<?php
2
4
8
9class Cache
10{
11 private const TTL = 3600;
12 private int $userId;
13
14 public function __construct(int $userId)
15 {
16 $this->userId = $userId;
17 }
18
29 public static function invalidateCache(int $id, array $fields = [], array $fieldsOld = []): EventResult
30 {
31 // TODO: spaces stub
32 return new EventResult(EventResult::SUCCESS, [], 'socialnetwork');
33
34 $userId = (int)($fields['USER_ID'] ?? 0);
35 if ($userId)
36 {
37 $userCache = new self($userId);
38 $userCache->fillUserSpaces();
39 $userCache->fillUserSpacesInvitations();
40 }
41
42 return new EventResult(EventResult::SUCCESS, [], 'socialnetwork');
43 }
44
45 public function getUserSpaceIds(): array
46 {
47 $cache = \Bitrix\Main\Data\Cache::createInstance();
48 if ($cache->initCache(self::TTL, $this->getUserSpacesKey(), $this->getUserSpacesDir()))
49 {
50 return $cache->getVars();
51 }
52
53 return $this->fillUserSpaces();
54 }
55
56 public function fillUserSpaces(): array
57 {
58 $userSpaceIds = (new Provider($this->userId))->getMySpaceIds();
59 // append common space
60 $userSpaceIds[] = 0;
61
62 $cache = \Bitrix\Main\Data\Cache::createInstance();
63 $cache->initCache(self::TTL, $this->getUserSpacesKey(), $this->getUserSpacesDir());
64 $cache->startDataCache();
65 $cache->forceRewriting(true);
66 $cache->endDataCache($userSpaceIds);
67
68 return $userSpaceIds;
69 }
70
71 public function getUserInvitationIds(): array
72 {
73 $cache = \Bitrix\Main\Data\Cache::createInstance();
74 if ($cache->initCache(self::TTL, $this->getUserSpacesInvitationKey(), $this->getUserSpacesInvitationDir()))
75 {
76 return $cache->getVars();
77 }
78
79 return $this->fillUserSpacesInvitations();
80 }
81
83 {
84 $invitations = [];
85
86 foreach ((new InvitationManager($this->userId))->getInvitations()->toArray() as $invitation)
87 {
88 $invitations[] = $invitation->getSpaceId();
89 }
90
91 $cache = \Bitrix\Main\Data\Cache::createInstance();
92 $cache->initCache(self::TTL, $this->getUserSpacesInvitationKey(), $this->getUserSpacesInvitationDir());
93 $cache->startDataCache();
94 $cache->endDataCache($invitations);
95
96 return $invitations;
97 }
98
99 public function isSameLeftMenuTotal(string $code, int $value): bool
100 {
101 global $CACHE_MANAGER;
102
103 $cache = $CACHE_MANAGER->Get('user_counter' . $this->userId);
104 if (!$cache)
105 {
106 return false;
107 }
108
109 foreach ($cache as $item)
110 {
111 if (
112 $item['CODE'] === $code
113 && $item['SITE_ID'] === '**'
114 && (int)$item['CNT'] === $value
115 )
116 {
117 return true;
118 }
119 }
120
121 return false;
122 }
123
124 private function getUserSpacesKey(): string
125 {
126 return 'user_spaces' . $this->userId;
127 }
128
129 private function getUserSpacesDir(): string
130 {
131 $key = $this->getUserSpacesKey();
132
133 return '/spaces/' . substr(md5($key),2,2) . '/' . $key . '/';
134 }
135
136 private function getUserSpacesInvitationKey(): string
137 {
138 return 'user_spaces_invitations' . $this->userId;
139 }
140
141 private function getUserSpacesInvitationDir(): string
142 {
143 $key = $this->getUserSpacesInvitationKey();
144
145 return '/spaces/' . substr(md5($key),2,2) . '/' . $key . '/';
146 }
147}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
isSameLeftMenuTotal(string $code, int $value)
Определения cache.php:99
static invalidateCache(int $id, array $fields=[], array $fieldsOld=[])
Определения cache.php:29
global $CACHE_MANAGER
Определения clear_component_cache.php:7
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(empty($signedUserToken)) $key
Определения quickway.php:257
$fields
Определения yandex_run.php:501