25 $config = \Bitrix\Main\Config\Configuration::getValue(
"cache");
27 if ($config && is_array($config))
29 if (isset($config[
"use_lock"]))
31 $this->useLock = (bool)$config[
"use_lock"];
34 if (isset($config[
"sid"]) && ($config[
"sid"] !=
""))
36 $this->sid = $config[
"sid"];
41 $this->ttlMultiplier = (integer)$config[
"ttl_multiplier"];
45 if (!empty($options) && isset($options[
'actual_data']))
47 $this->useLock = !((bool) $options[
'actual_data']);
54 $this->ttlMultiplier = 1;
110 protected function lock($baseDir, $initDir, $key, $TTL)
113 isset(self::$locks[$baseDir])
114 && isset(self::$locks[$baseDir][$initDir])
115 && isset(self::$locks[$baseDir][$initDir][$key])
120 elseif (xcache_get($key))
126 $lock = xcache_inc($key, 1, intval($TTL));
129 self::$locks[$baseDir][$initDir][$key] =
true;
148 protected function unlock($baseDir, $initDir =
false, $key =
false, $TTL = 0)
154 xcache_set($key, 1, intval($TTL));
161 unset(self::$locks[$baseDir][$initDir][$key]);
163 elseif ($initDir !==
false)
165 if (isset(self::$locks[$baseDir][$initDir]))
167 foreach (self::$locks[$baseDir][$initDir] as $subKey)
169 $this->
unlock($baseDir, $initDir, $subKey, $TTL);
171 unset(self::$locks[$baseDir][$initDir]);
174 elseif ($baseDir !==
false)
176 if (isset(self::$locks[$baseDir]))
178 foreach (self::$locks[$baseDir] as $subInitDir)
180 $this->
unlock($baseDir, $subInitDir,
false, $TTL);
195 public function clean($baseDir, $initDir =
false, $filename =
false)
200 $baseDirVersion = xcache_get($this->sid.$baseDir);
201 if($baseDirVersion ===
null)
206 if($initDir !==
false)
208 $initDirVersion = xcache_get($baseDirVersion.
"|".$initDir);
209 if($initDirVersion ===
null)
216 $initDirVersion =
"";
219 $key = $baseDirVersion.
"|".$initDirVersion.
"|".$filename;
226 $baseDirVersion = xcache_get($this->sid.$baseDir);
227 if($baseDirVersion ===
null)
232 xcache_unset($baseDirVersion.
"|".$initDir);
236 xcache_unset($this->sid.$baseDir);
239 $this->
unlock($baseDir, $initDir, $key.
"~");
253 public function read(&$allVars, $baseDir, $initDir, $filename, $TTL)
255 $baseDirVersion = xcache_get($this->sid.$baseDir);
256 if ($baseDirVersion ===
null)
259 if ($initDir !==
false)
261 $initDirVersion = xcache_get($baseDirVersion.
"|".$initDir);
262 if ($initDirVersion ===
null)
267 $initDirVersion =
"";
270 $key = $baseDirVersion.
"|".$initDirVersion.
"|".$filename;
271 $allVars = xcache_get($key);
273 if ($allVars ===
null)
281 if ($this->
lock($baseDir, $initDir, $key.
"~", $TTL))
287 $this->
read = mb_strlen($allVars);
288 $allVars = unserialize($allVars);
305 public function write($allVars, $baseDir, $initDir, $filename, $TTL)
307 $baseDirVersion = xcache_get($this->sid.$baseDir);
308 if ($baseDirVersion ===
null)
310 $baseDirVersion = md5(mt_rand());
311 if (!xcache_set($this->sid.$baseDir, $baseDirVersion))
315 if ($initDir !==
false)
317 $initDirVersion = xcache_get($baseDirVersion.
"|".$initDir);
318 if ($initDirVersion ===
null)
320 $initDirVersion = md5(mt_rand());
321 if (!xcache_set($baseDirVersion.
"|".$initDir, $initDirVersion))
327 $initDirVersion =
"";
330 $allVars = serialize($allVars);
331 $this->written = mb_strlen($allVars);
333 $key = $baseDirVersion.
"|".$initDirVersion.
"|".$filename;
334 xcache_set($key, $allVars, intval($TTL) * $this->ttlMultiplier);
338 $this->
unlock($baseDir, $initDir, $key.
"~", $TTL);