Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
cachedpool.php
1<?php
3
6
12{
14 protected $pool;
16 protected $cache;
18 protected $isItemChanged = false;
19
28 public function __construct(Pool $pool, int $ttl, string $cacheId, Cache $cache, EventManager $eventManager)
29 {
30 $this->pool = $pool;
31 parent::__construct($ttl, $cacheId, $cache, $eventManager);
32 }
33
34 public function loadDataFromCache(): void
35 {
36 $items = $this->cache->getVars()['items'];
37 if(is_array($items))
38 {
39 $this->pool->setItems($items);
40 }
41 }
42
43 public function saveDataToCache(): void
44 {
45 if($this->isItemChanged)
46 {
47 $this->cache->forceRewriting(true);
48 $this->cache->startDataCache();
49 $this->cache->endDataCache(['items' => $this->pool->getItems()]);
50 }
51 }
52
57 public function getItem(string $key)
58 {
59 return $this->pool->getItem($key);
60 }
61
66 public function addItem(string $key, $value): void
67 {
68 $this->pool->addItem($key, $value);
69 $this->isItemChanged = true;
70 }
71
75 public function deleteItem(string $key): void
76 {
77 $this->pool->deleteItem($key);
78 $this->isItemChanged = true;
79 }
80
81 public function cleanItems(): void
82 {
83 $this->pool->cleanItems();
84 $this->isItemChanged = true;
85 }
86}
__construct(Pool $pool, int $ttl, string $cacheId, Cache $cache, EventManager $eventManager)
addItem(string $key, $value)