Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
CacheManager.php
1<?php
2
4
6
8{
9 public const CHANNEL_CACHE_ENTITY_ID = 'channel';
10 private const BASE_CACHE_DIR = '/messageservice/';
11 private const CACHE_TTL = 86400; //one hour
12 private Cache $cache;
13 private string $providerId;
14
18 public function __construct(string $providerId)
19 {
20 $this->cache = Cache::createInstance();
21 $this->providerId = $providerId;
22 }
23
28 public function getTtl(string $entityId): int
29 {
30 return self::CACHE_TTL;
31 }
32
38 public function getValue(string $entityId): array
39 {
40 $result = [];
41 if ($this->cache->initCache($this->getTtl($entityId), $entityId, $this->getCacheDir()))
42 {
43 $result = $this->cache->getVars();
44 }
45
46 return $result;
47 }
48
49 private function getCacheDir(): string
50 {
51 return self::BASE_CACHE_DIR . $this->providerId;
52 }
53
54 public function setValue(string $entityId, array $value): CacheManager
55 {
56 $cacheName = $entityId;
57
58 $this->cache->clean($cacheName, $this->getCacheDir());
59
60 $this->cache->initCache($this->getTtl($entityId), $cacheName, $this->getCacheDir());
61 $this->cache->startDataCache();
62 $this->cache->endDataCache($value);
63
64 return $this;
65 }
66
67 public function deleteValue(string $entityId): CacheManager
68 {
69 $cacheName = $entityId;
70
71 $this->cache->clean($cacheName, $this->getCacheDir());
72
73 return $this;
74 }
75}
setValue(string $entityId, array $value)