1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
JobCache.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
13
15{
16 private const TTL = 86400 * 30; // 30 days
17 private const PATH = 'sonet/onboarding_user_option';
18 private const ID_PREFIX = 'promo_queue_by_user_id_';
19
20 public function getByUserId(int $userId): ?JobCollection
21 {
22 $cache = Cache::createInstance();
23 $cacheId = $this->getCacheId($userId);
24
25 if ($cache->initCache(self::TTL, $cacheId, self::PATH))
26 {
27 $jobs = $cache->getVars();
28 if (!is_array($jobs))
29 {
30 return null;
31 }
32
33 return JobCollection::mapFromArray($jobs);
34 }
35
36 return null;
37 }
38
39 private function getCacheId(int $userId): string
40 {
41 return self::ID_PREFIX . $userId;
42 }
43
49 public function save(array $sortedByUserJobs): void
50 {
51 if (empty($sortedByUserJobs))
52 {
53 return;
54 }
55
56 $cache = Cache::createInstance();
57
58 foreach ($sortedByUserJobs as $userId => $jobs)
59 {
60 $this->cleanByUserIds($userId);
61 $cacheId = $this->getCacheId($userId);
62
63 $cache->startDataCache(self::TTL, $cacheId, self::PATH);
64 $this->registerCollabTags($cacheId, $jobs);
65 $cache->endDataCache($jobs->toArray());
66 }
67 }
68
73 private function registerCollabTags(string $cacheId, JobCollection $jobs): void
74 {
75 $taggedCache = Application::getInstance()->getTaggedCache();
76
77 $collabIds = $jobs->getCollabIdList();
78
79 foreach ($collabIds as $collabId)
80 {
81 $taggedCache->startTagCache(self::PATH. '/' . Cache::getPath($cacheId));
82 $taggedCache->registerTag($this->getCacheTag($collabId));
83 $taggedCache->endTagCache();
84 }
85 }
86
87 private function getCacheTag(int $collabId): string
88 {
89 return 'sonet_onboarding_collab_id_' . $collabId;
90 }
91
92 public function cleanByUserIds(int ...$userIds): void
93 {
94 $cache = Cache::createInstance();
95
96 foreach ($userIds as $userId)
97 {
98 $cacheId = $this->getCacheId($userId);
99 $cache->clean($cacheId, self::PATH);
100 }
101 }
102
108 public function cleanByJobCollection(array $sortedByUserJobs): void
109 {
110 foreach ($sortedByUserJobs as $userId => $jobs)
111 {
112 $cachedJobs = $this->getByUserId($userId);
113
114 if (null !== $cachedJobs)
115 {
116 $cachedJobs->cleanIntersectingJobs($jobs);
117 $this->save([$userId => $cachedJobs]);
118 }
119 }
120 }
121
127 public function cleanByCollabIds(int ...$collabIds): void
128 {
129 $taggedCache = Application::getInstance()->getTaggedCache();
130
131 foreach ($collabIds as $collabId)
132 {
133 $taggedCache->clearByTag($this->getCacheTag($collabId));
134 }
135 }
136}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getPath()
Определения filesystementry.php:80
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804