1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
taggedcache.php
См. документацию.
1
<?php
8
9
namespace
Bitrix\Main\Data;
10
11
use Bitrix\Main\Application;
12
use Bitrix\Main\ArgumentException;
13
use Bitrix\Main\Data\Internal\CacheTagTable;
14
use Bitrix\Main\ObjectPropertyException;
15
use Bitrix\Main\SystemException;
16
17
class
TaggedCache
18
{
19
protected
int
$limit
= 200;
20
protected
int
$delLimit
= 100;
21
protected
array
$cacheStack
= [];
22
protected
array
$cacheTag
= [];
23
protected
string
$salt
=
''
;
24
protected
bool
$wasTagged
=
false
;
25
protected
ConnectionPool
$pool
;
26
27
public
function
__construct
()
28
{
29
$this->pool =
Application::getInstance
()->getConnectionPool();
30
}
31
32
protected
function
initDbCache
(
$path
): void
33
{
34
if
(!isset($this->cacheTag[
$path
]))
35
{
36
$this->cacheTag[
$path
] = [];
37
$this->pool->useMasterOnly(
true
);
38
39
$tags =
CacheTagTable::query
()
40
->setSelect([
'ID'
,
'TAG'
])
41
->where(
'SITE_ID'
,
SITE_ID
)
42
->where(
'CACHE_SALT'
, $this->salt)
43
->where(
'RELATIVE_PATH'
,
$path
)
44
->fetchAll();
45
46
foreach
($tags as $tag)
47
{
48
$this->cacheTag[
$path
][$tag[
'TAG'
]] =
true
;
49
}
50
51
$this->pool->useMasterOnly(
false
);
52
unset($tags, $tag);
53
}
54
}
55
56
protected
function
initCompSalt
(): void
57
{
58
if
($this->salt ==
''
)
59
{
60
$this->salt = Cache::getSalt();
61
}
62
}
63
64
public
function
startTagCache
($relativePath) : void
65
{
66
array_unshift($this->cacheStack, [$relativePath, []]);
67
}
68
73
public
function
endTagCache
(): void
74
{
75
$this->
initCompSalt
();
76
if
($this->wasTagged)
77
{
78
$cnt = 0;
79
$tags = [];
80
$this->pool->useMasterOnly(
true
);
81
82
foreach
($this->cacheStack as $cache)
83
{
84
$path
= $cache[0];
85
if
(
$path <>
''
)
86
{
87
$this->
initDbCache
(
$path
);
88
foreach
($cache[1] as $tag => $t)
89
{
90
if
(!isset($this->cacheTag[
$path
][$tag]))
91
{
92
$cnt++;
93
$tags[] = [
94
'TAG'
=> $tag,
95
'RELATIVE_PATH'
=>
$path
,
96
'SITE_ID'
=>
SITE_ID
,
97
'CACHE_SALT'
=>
$this->salt
98
];
99
100
$this->cacheTag[
$path
][$tag] =
true
;
101
}
102
103
if
($cnt > $this->limit)
104
{
105
CacheTagTable::addMulti
($tags,
true
);
106
$cnt = 0;
107
$tags = [];
108
}
109
}
110
}
111
}
112
113
array_shift($this->cacheStack);
114
115
if
(!empty($tags))
116
{
117
CacheTagTable::addMulti
($tags,
true
);
118
}
119
120
$this->pool->useMasterOnly(
false
);
121
}
122
}
123
124
public
function
abortTagCache
(): void
125
{
126
array_shift($this->cacheStack);
127
}
128
129
public
function
registerTag
($tag): void
130
{
131
if
(!empty($this->cacheStack))
132
{
133
$this->cacheStack = array_map(
134
function
(
$val
) use ($tag) {
135
$val
[1][$tag] =
true
;
136
return
$val
;
137
},
$this->cacheStack
138
);
139
140
$this->wasTagged =
true
;
141
}
142
}
143
149
public
function
clearByTag
($tag): void
150
{
151
$cnt = 0;
152
$id = [];
153
$paths
= [];
154
155
$this->pool->useMasterOnly(
true
);
156
$cache = Cache::createInstance();
157
158
$query
=
CacheTagTable::query
()->setSelect([
'ID'
,
'RELATIVE_PATH'
]);
159
160
if
($tag ===
true
)
161
{
162
$query
->whereNot(
'TAG'
,
'*'
);
163
}
164
else
165
{
166
$query
->where(
'TAG'
, $tag);
167
}
168
169
$res
=
$query
->exec();
170
while
(
$ar
=
$res
->fetch())
171
{
172
$cnt++;
173
$id[] =
$ar
[
'ID'
];
174
$paths
[
$ar
[
'RELATIVE_PATH'
]] = 1;
175
if
($cnt > $this->delLimit)
176
{
177
$this->
deleteTags
($cache, $id,
$paths
);
178
179
$cnt = 0;
180
$id = [];
181
$paths
= [];
182
}
183
}
184
185
if
(!empty($id))
186
{
187
$this->
deleteTags
($cache, $id,
$paths
);
188
}
189
190
$this->pool->useMasterOnly(
false
);
191
unset(
$res
,
$paths
,
$path
, $id);
192
}
193
194
protected
function
deleteTags
(
Cache
$cache,
array
$id,
array
$paths
): void
195
{
196
CacheTagTable::deleteByFilter([
'@ID'
=> $id]);
197
CacheTagTable::deleteByFilter([
'@RELATIVE_PATH'
=> array_keys(
$paths
)]);
198
199
foreach
(
$paths
as
$path
=> $v)
200
{
201
$cache->
cleanDir
(
$path
);
202
unset($this->cacheTag[
$path
]);
203
}
204
}
205
206
public
function
deleteAllTags
(): void
207
{
208
CacheTagTable::cleanTable
();
209
}
210
}
$path
$path
Определения
access_edit.php:21
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\Data\Cache\cleanDir
cleanDir($initDir=false, $baseDir='cache')
Определения
cache.php:263
Bitrix\Main\Data\ConnectionPool
Определения
connectionpool.php:20
Bitrix\Main\Data\Internal\CacheTagTable\cleanTable
static cleanTable()
Определения
cachetagtable.php:66
Bitrix\Main\Data\TaggedCache
Определения
taggedcache.php:18
Bitrix\Main\Data\TaggedCache\$limit
int $limit
Определения
taggedcache.php:19
Bitrix\Main\Data\TaggedCache\clearByTag
clearByTag($tag)
Определения
taggedcache.php:149
Bitrix\Main\Data\TaggedCache\__construct
__construct()
Определения
taggedcache.php:27
Bitrix\Main\Data\TaggedCache\$pool
ConnectionPool $pool
Определения
taggedcache.php:25
Bitrix\Main\Data\TaggedCache\abortTagCache
abortTagCache()
Определения
taggedcache.php:124
Bitrix\Main\Data\TaggedCache\initDbCache
initDbCache($path)
Определения
taggedcache.php:32
Bitrix\Main\Data\TaggedCache\initCompSalt
initCompSalt()
Определения
taggedcache.php:56
Bitrix\Main\Data\TaggedCache\startTagCache
startTagCache($relativePath)
Определения
taggedcache.php:64
Bitrix\Main\Data\TaggedCache\$cacheTag
array $cacheTag
Определения
taggedcache.php:22
Bitrix\Main\Data\TaggedCache\$delLimit
int $delLimit
Определения
taggedcache.php:20
Bitrix\Main\Data\TaggedCache\$cacheStack
array $cacheStack
Определения
taggedcache.php:21
Bitrix\Main\Data\TaggedCache\$salt
string $salt
Определения
taggedcache.php:23
Bitrix\Main\Data\TaggedCache\registerTag
registerTag($tag)
Определения
taggedcache.php:129
Bitrix\Main\Data\TaggedCache\$wasTagged
bool $wasTagged
Определения
taggedcache.php:24
Bitrix\Main\Data\TaggedCache\endTagCache
endTagCache()
Определения
taggedcache.php:73
Bitrix\Main\Data\TaggedCache\deleteAllTags
deleteAllTags()
Определения
taggedcache.php:206
Bitrix\Main\Data\TaggedCache\deleteTags
deleteTags(Cache $cache, array $id, array $paths)
Определения
taggedcache.php:194
Bitrix\Main\ORM\Data\DataManager\query
static query()
Определения
datamanager.php:549
Bitrix\Main\ORM\Data\DataManager\addMulti
static addMulti($rows, $ignoreEvents=false)
Определения
datamanager.php:1041
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$query
$query
Определения
get_search.php:11
Bitrix\Main\Data\Cache
Определения
keyvalueengine.php:3
$ar
$ar
Определения
options.php:199
$paths
$paths
Определения
options.php:2080
$val
$val
Определения
options.php:1793
SITE_ID
const SITE_ID
Определения
sonet_set_content_view.php:12
bitrix
modules
main
lib
data
taggedcache.php
Создано системой
1.14.0