1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CollabCache.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
10
12{
13 use SingletonTrait;
14
15 private const TTL = 86400 * 30; // 30 days
16 private const PATH = 'sonet/collab_onboarding';
17 private const ID_PREFIX = 'first_added_member_data';
18
19 public function getFirstAddedMemberData(int $collabId): ?FirstAddedMemberData
20 {
21 $cache = Cache::createInstance();
22 $cacheId = $this->getCacheId($collabId);
23
24 if ($cache->initCache(self::TTL, $cacheId, self::PATH))
25 {
26 $firstAddedData = $cache->getVars();
27 if (!is_array($firstAddedData))
28 {
29 return null;
30 }
31
32 return FirstAddedMemberData::createFromArray($firstAddedData);
33 }
34
35 return null;
36 }
37
38 public function save(FirstAddedMemberData $firstAddedData): void
39 {
40 $cache = Cache::createInstance();
41 $cacheId = $this->getCacheId($firstAddedData->collabId);
42
43 $cache->clean($cacheId, self::PATH);
44
45 $cache->startDataCache(self::TTL, $cacheId, self::PATH);
46 $cache->endDataCache($firstAddedData->toArray());
47 }
48
49 private function getCacheId(int $collabId): string
50 {
51 return self::ID_PREFIX . $collabId;
52 }
53}
save(FirstAddedMemberData $firstAddedData)
Определения CollabCache.php:38
trait SingletonTrait
Определения singletontrait.php:8