Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
CacheManager.php
1
<?php
2
3
namespace
Bitrix\MessageService\Providers
;
4
5
use
Bitrix\Main\Data\Cache
;
6
7
class
CacheManager
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
}
Bitrix\Main\Data\Cache
Definition
cache.php:16
Bitrix\MessageService\Providers\CacheManager
Definition
CacheManager.php:8
Bitrix\MessageService\Providers\CacheManager\getTtl
getTtl(string $entityId)
Definition
CacheManager.php:28
Bitrix\MessageService\Providers\CacheManager\__construct
__construct(string $providerId)
Definition
CacheManager.php:18
Bitrix\MessageService\Providers\CacheManager\getValue
getValue(string $entityId)
Definition
CacheManager.php:38
Bitrix\MessageService\Providers\CacheManager\deleteValue
deleteValue(string $entityId)
Definition
CacheManager.php:67
Bitrix\MessageService\Providers\CacheManager\CHANNEL_CACHE_ENTITY_ID
const CHANNEL_CACHE_ENTITY_ID
Definition
CacheManager.php:9
Bitrix\MessageService\Providers\CacheManager\setValue
setValue(string $entityId, array $value)
Definition
CacheManager.php:54
Bitrix\MessageService\Providers
modules
messageservice
lib
Providers
CacheManager.php
Создано системой
1.10.0