1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cacheenginememcache.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Data;
4
5use Bitrix\Main\Config\Configuration;
6use Bitrix\Main\Data\LocalStorage\Storage;
7
9{
10 public function getConnectionName(): string
11 {
12 return 'cache.memcache';
13 }
14
15 public static function getConnectionClass()
16 {
17 return MemcacheConnection::class;
18 }
19
20 protected function configure($options = []): array
21 {
22 $config = parent::configure($options);
23
24 $cacheConfig = Configuration::getValue('cache');
25
26 $config['persistent'] = true;
27 if (isset($cacheConfig['persistent']) && $cacheConfig['persistent'] == 0)
28 {
29 $config['persistent'] = false;
30 }
31
32 if (isset($cacheConfig['connectionTimeout']))
33 {
34 $config['connectionTimeout'] = (int)$cacheConfig['connectionTimeout'];
35 }
36
37 return $config;
38 }
39
40 protected static function getExpire($ttl)
41 {
42 $ttl = (int) $ttl;
43 if ($ttl > 2592000)
44 {
45 $ttl = microtime(1) + $ttl;
46 }
47
48 return $ttl;
49 }
50
51 public function set($key, $ttl, $value)
52 {
53 $ttl = self::getExpire($ttl);
54 return self::$engine->set($key, $value, 0, $ttl);
55 }
56
57 public function get($key)
58 {
59 return self::$engine->get($key);
60 }
61
62 public function del($key)
63 {
64 if (is_array($key))
65 {
66 foreach ($key as $item)
67 {
68 self::$engine->delete($item);
69 }
70 }
71 else
72 {
73 self::$engine->delete($key);
74 }
75 }
76
77 public function setNotExists($key, $ttl, $value)
78 {
79 $ttl = self::getExpire($ttl);
80 return self::$engine->add($key, $value, null, $ttl);
81 }
82
83 public function checkInSet($key, $value) : bool
84 {
85 $list = self::$engine->get($key);
86
87 if (!is_array($list))
88 {
89 $list = [];
90 }
91
92 if (array_key_exists($value, $list))
93 {
94 return true;
95 }
96
97 return false;
98 }
99
100 public function addToSet($key, $value)
101 {
102 $list = self::$engine->get($key);
103
104 if (!is_array($list))
105 {
106 $list = [];
107 }
108
109 if (!array_key_exists($value, $list))
110 {
111 $list[$value] = 1;
112 $this->set($key, 0, $list);
113 }
114 }
115
116 public function getSet($key): array
117 {
118 $list = self::$engine->get($key);
119 if (!is_array($list) || empty($list))
120 {
121 return [];
122 }
123
124 return array_keys($list);
125 }
126
127 public function deleteBySet($key, $prefix = '')
128 {
129 $list = self::$engine->get($key);
130 self::$engine->delete($key);
131
132 if (is_array($list) && !empty($list))
133 {
134 array_walk($list, function ($value, $key) {
135 self::$engine->delete($key);
136 });
137 unset($list);
138 }
139 }
140
141 public function delFromSet($key, $member)
142 {
143 $list = self::$engine->get($key);
144
145 if (is_array($list) && !empty($list))
146 {
147 $rewrite = false;
148 if (!is_array($member))
149 {
150 $member = [0 => $member];
151 }
152
153 foreach ($member as $keyID)
154 {
155 if (array_key_exists($keyID, $list))
156 {
157 $rewrite = true;
158 unset($list[$keyID]);
159 }
160 }
161
162 if ($rewrite)
163 {
164 if (empty($list))
165 {
166 self::$engine->delete($key);
167 }
168 else
169 {
170 $this->set($key, 0, $list);
171 }
172 }
173 unset($list);
174 }
175 }
176}
deleteBySet($key, $prefix='')
Определения cacheenginememcache.php:127
setNotExists($key, $ttl, $value)
Определения cacheenginememcache.php:77
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$config
Определения quickway.php:69
if(empty($signedUserToken)) $key
Определения quickway.php:257