1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
memcachedstorage.php
См. документацию.
1<?php
2namespace Bitrix\Main\Composite\Data;
3
4use Bitrix\Main\Composite\Helper;
5use Bitrix\Main\Composite\MemcachedResponse;
6
13{
14 private $memcached = null;
15 private $props = null;
16 private $compression = true;
17
19 {
20 parent::__construct($cacheKey, $configuration, $htmlCacheOptions);
22 if ($this->memcached !== null)
23 {
24 $this->memcached->setCompressThreshold(0);
25 }
26
27 $this->compression = !isset($htmlCacheOptions["MEMCACHE_COMPRESSION"]) || $htmlCacheOptions["MEMCACHE_COMPRESSION"] !== "N";
28 }
29
30 public function write($content, $md5)
31 {
32 $flags = 0;
33 if ($this->compression)
34 {
36 $content = gzencode($content, 4);
37 }
38
39 if (!$this->memcached || !$this->memcached->set($this->cacheKey, $content, $flags))
40 {
41 return false;
42 }
43
44 $this->props = new \stdClass();
45 $this->props->mtime = time();
46 $this->props->etag = md5($this->cacheKey.$this->props->size.$this->props->mtime);
47 $this->props->type = "text/html; charset=".LANG_CHARSET;
48 $this->props->md5 = $md5;
49 $this->props->gzip = $this->compression;
50
51 $this->props->size = strlen($content);
52 $this->props->size += strlen(serialize($this->props));
53
54 $this->memcached->set("~".$this->cacheKey, $this->props);
55
56 return $this->props->size;
57 }
58
59 public function read()
60 {
61 if ($this->memcached !== null)
62 {
63 $flags = 0;
64 $content = $this->memcached->get($this->cacheKey, $flags);
65 return $flags & MemcachedResponse::MEMCACHED_GZIP_FLAG ? Helper::gzdecode($content) : $content;
66 }
67
68 return false;
69 }
70
71 public function exists()
72 {
73 return $this->getProps() !== false;
74 }
75
76 public function delete()
77 {
78 if ($this->memcached && $this->memcached->delete($this->cacheKey))
79 {
80 $size = $this->getProp("size");
81 $this->deleteProps();
82 return $size;
83 }
84
85 return false;
86 }
87
88 public function deleteAll()
89 {
90 if ($this->memcached)
91 {
92 return $this->memcached->flush();
93 }
94
95 return false;
96 }
97
102 public function getMd5()
103 {
104 return $this->getProp("md5");
105 }
106
111 public function shouldCountQuota()
112 {
113 return false;
114 }
115
120 public function getLastModified()
121 {
122 return $this->getProp("mtime");
123 }
124
130 public function getSize()
131 {
132 return $this->getProp("size");
133 }
134
140 protected function getProps()
141 {
142 if ($this->props === null)
143 {
144 if ($this->memcached !== null)
145 {
146 $props = $this->memcached->get("~".$this->cacheKey);
147 $this->props = is_object($props) ? $props : false;
148 }
149 else
150 {
151 $this->props = false;
152 }
153 }
154
155 return $this->props;
156 }
157
163 protected function deleteProps()
164 {
165 if ($this->memcached)
166 {
167 $this->props = false;
168 return $this->memcached->delete("~".$this->cacheKey);
169 }
170
171 return false;
172 }
173
180 protected function getProp($property)
181 {
182 $props = $this->getProps();
183 if ($props !== false && isset($props->{$property}))
184 {
185 return $props->{$property};
186 }
187
188 return false;
189 }
190}
191
192class_alias("Bitrix\\Main\\Composite\\Data\\MemcachedStorage", "Bitrix\\Main\\Data\\StaticHtmlMemcachedStorage");
__construct($cacheKey, array $configuration, array $htmlCacheOptions)
Определения memcachedstorage.php:18
static getConnection(array $configuration, array $htmlCacheOptions)
Определения responder.php:673
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$md5
Определения result_rec.php:12
$props
Определения template.php:269