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