1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
memcachedstorage.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Composite\Data;
3
4
use Bitrix\Main\Composite\Helper;
5
use Bitrix\Main\Composite\MemcachedResponse;
6
12
final
class
MemcachedStorage
extends
AbstractStorage
13
{
14
private
$memcached =
null
;
15
private
$props =
null
;
16
private
$compression =
true
;
17
18
public
function
__construct
(
$cacheKey
,
array
$configuration
,
array
$htmlCacheOptions
)
19
{
20
parent::__construct(
$cacheKey
,
$configuration
,
$htmlCacheOptions
);
21
$this->memcached =
MemcachedResponse::getConnection
(
$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
{
35
$flags =
MemcachedResponse::MEMCACHED_GZIP_FLAG
;
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
192
class_alias(
"Bitrix\\Main\\Composite\\Data\\MemcachedStorage"
,
"Bitrix\\Main\\Data\\StaticHtmlMemcachedStorage"
);
Bitrix\Main\Composite\Data\AbstractStorage
Определения
abstractstorage.php:10
Bitrix\Main\Composite\Data\AbstractStorage\$cacheKey
$cacheKey
Определения
abstractstorage.php:11
Bitrix\Main\Composite\Data\AbstractStorage\$htmlCacheOptions
$htmlCacheOptions
Определения
abstractstorage.php:13
Bitrix\Main\Composite\Data\AbstractStorage\$configuration
$configuration
Определения
abstractstorage.php:12
Bitrix\Main\Composite\Data\MemcachedStorage
Определения
memcachedstorage.php:13
Bitrix\Main\Composite\Data\MemcachedStorage\deleteProps
deleteProps()
Определения
memcachedstorage.php:163
Bitrix\Main\Composite\Data\MemcachedStorage\read
read()
Определения
memcachedstorage.php:59
Bitrix\Main\Composite\Data\MemcachedStorage\__construct
__construct($cacheKey, array $configuration, array $htmlCacheOptions)
Определения
memcachedstorage.php:18
Bitrix\Main\Composite\Data\MemcachedStorage\getSize
getSize()
Определения
memcachedstorage.php:130
Bitrix\Main\Composite\Data\MemcachedStorage\getMd5
getMd5()
Определения
memcachedstorage.php:102
Bitrix\Main\Composite\Data\MemcachedStorage\write
write($content, $md5)
Определения
memcachedstorage.php:30
Bitrix\Main\Composite\Data\MemcachedStorage\getLastModified
getLastModified()
Определения
memcachedstorage.php:120
Bitrix\Main\Composite\Data\MemcachedStorage\deleteAll
deleteAll()
Определения
memcachedstorage.php:88
Bitrix\Main\Composite\Data\MemcachedStorage\exists
exists()
Определения
memcachedstorage.php:71
Bitrix\Main\Composite\Data\MemcachedStorage\getProp
getProp($property)
Определения
memcachedstorage.php:180
Bitrix\Main\Composite\Data\MemcachedStorage\shouldCountQuota
shouldCountQuota()
Определения
memcachedstorage.php:111
Bitrix\Main\Composite\Data\MemcachedStorage\getProps
getProps()
Определения
memcachedstorage.php:140
Bitrix\Main\Composite\MemcachedResponse\MEMCACHED_GZIP_FLAG
const MEMCACHED_GZIP_FLAG
Определения
responder.php:547
Bitrix\Main\Composite\MemcachedResponse\getConnection
static getConnection(array $configuration, array $htmlCacheOptions)
Определения
responder.php:673
$content
$content
Определения
commerceml.php:144
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$md5
$md5
Определения
result_rec.php:12
$props
$props
Определения
template.php:269
bitrix
modules
main
lib
composite
data
memcachedstorage.php
Создано системой
1.14.0