1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
managedcache.php
См. документацию.
1
<?php
2
9
10
namespace
Bitrix\Main\Data;
11
12
use Bitrix\Main;
13
14
class
ManagedCache
15
{
17
protected
$cache
= [];
18
protected
$cacheInit
= [];
19
protected
$cachePath
= [];
20
protected
$vars
= [];
21
protected
$ttl
= [];
22
protected
$dbType
;
23
24
public
function
__construct
()
25
{
26
$this->dbType = strtoupper(
Main
\
Application::getInstance
()->getConnection()->getType());
27
}
28
29
// Tries to read cached variable value from the file
30
// Returns true on success
31
// otherwise returns false
32
public
function
read
(
$ttl
, $uniqueId, $tableId =
false
)
33
{
34
if
(!isset($this->cacheInit[$uniqueId]))
35
{
36
$this->cache[$uniqueId] = Cache::createInstance();
37
$this->cachePath[$uniqueId] = $this->dbType . ($tableId ===
false
?
""
:
"/"
. $tableId);
38
$this->ttl[$uniqueId] =
$ttl
;
39
$this->cacheInit[$uniqueId] = $this->cache[$uniqueId]->initCache(
$ttl
, $uniqueId, $this->cachePath[$uniqueId],
"managed_cache"
);
40
}
41
return
$this->cacheInit[$uniqueId] || array_key_exists($uniqueId, $this->vars);
42
}
43
44
public
function
getImmediate
(
$ttl
, $uniqueId, $tableId =
false
)
45
{
46
$cache
= Cache::createInstance();
47
$cachePath
= $this->dbType . ($tableId ===
false
?
""
:
"/"
. $tableId);
48
49
if
(
$cache
->initCache(
$ttl
, $uniqueId,
$cachePath
,
"managed_cache"
))
50
{
51
return
$cache
->getVars();
52
}
53
return
false
;
54
}
55
63
public
function
get
($uniqueId)
64
{
65
if
(array_key_exists($uniqueId, $this->vars))
66
{
67
return
$this->vars[$uniqueId];
68
}
69
elseif
(isset($this->cacheInit[$uniqueId]) && $this->cacheInit[$uniqueId])
70
{
71
return
$this->cache[$uniqueId]->getVars();
72
}
73
else
74
{
75
return
false
;
76
}
77
}
78
79
// Sets new value to the variable
80
public
function
set
($uniqueId,
$val
)
81
{
82
if
(isset($this->cache[$uniqueId]))
83
{
84
$this->vars[$uniqueId] =
$val
;
85
}
86
}
87
88
public
function
setImmediate
($uniqueId,
$val
)
89
{
90
if
(isset($this->cache[$uniqueId]))
91
{
92
$cache
= Cache::createInstance();
93
$cache
->noOutput();
94
$cache
->startDataCache($this->ttl[$uniqueId], $uniqueId, $this->cachePath[$uniqueId],
$val
,
"managed_cache"
);
95
$cache
->endDataCache();
96
97
unset($this->cache[$uniqueId]);
98
unset($this->cacheInit[$uniqueId]);
99
unset($this->cachePath[$uniqueId]);
100
unset($this->vars[$uniqueId]);
101
}
102
}
103
104
// Marks cache entry as invalid
105
public
function
clean
($uniqueId, $tableId =
false
)
106
{
107
$cache
= Cache::createInstance();
108
$cache
->clean(
109
$uniqueId,
110
$this->dbType . ($tableId ===
false
?
""
:
"/"
. $tableId),
111
"managed_cache"
112
);
113
if
(isset($this->cache[$uniqueId]))
114
{
115
unset($this->cache[$uniqueId]);
116
unset($this->cacheInit[$uniqueId]);
117
unset($this->cachePath[$uniqueId]);
118
unset($this->vars[$uniqueId]);
119
}
120
}
121
122
// Marks cache entries associated with the table as invalid
123
public
function
cleanDir
($tableId)
124
{
125
$strPath = $this->dbType .
"/"
. $tableId;
126
foreach
($this->cachePath as $uniqueId => $Path)
127
{
128
if
($Path == $strPath)
129
{
130
unset($this->cache[$uniqueId]);
131
unset($this->cacheInit[$uniqueId]);
132
unset($this->cachePath[$uniqueId]);
133
unset($this->vars[$uniqueId]);
134
}
135
}
136
$cache
= Cache::createInstance();
137
$cache
->cleanDir($this->dbType .
"/"
. $tableId,
"managed_cache"
);
138
}
139
140
// Clears all managed_cache
141
public
function
cleanAll
()
142
{
143
$this->cache = [];
144
$this->cacheInit = [];
145
$this->cachePath = [];
146
$this->vars = [];
147
$this->ttl = [];
148
149
$cache
= Cache::createInstance();
150
$cache
->cleanDir(
false
,
"managed_cache"
);
151
}
152
153
// Use it to flush cache to the files.
154
// Causion: only at the end of all operations!
155
public
static
function
finalize
()
156
{
157
$cacheManager =
Main\Application::getInstance
()->getManagedCache();
158
$cache
= Cache::createInstance();
159
foreach
($cacheManager->cache as $uniqueId =>
$val
)
160
{
161
if
(array_key_exists($uniqueId, $cacheManager->vars))
162
{
163
$cache
->startDataCache($cacheManager->ttl[$uniqueId], $uniqueId, $cacheManager->cachePath[$uniqueId], $cacheManager->vars[$uniqueId],
"managed_cache"
);
164
$cache
->endDataCache();
165
}
166
}
167
}
168
169
public
function
getCompCachePath
($relativePath)
170
{
171
// TODO: global var!
172
global $BX_STATE;
173
174
if
($BX_STATE ===
"WA"
)
175
{
176
$salt = Cache::getSalt();
177
}
178
else
179
{
180
$salt =
"/"
. mb_substr(md5($BX_STATE), 0, 3);
181
}
182
183
$path
=
"/"
.
SITE_ID
. $relativePath . $salt;
184
return
$path
;
185
}
186
}
$path
$path
Определения
access_edit.php:21
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\Data\ManagedCache
Определения
managedcache.php:15
Bitrix\Main\Data\ManagedCache\clean
clean($uniqueId, $tableId=false)
Определения
managedcache.php:105
Bitrix\Main\Data\ManagedCache\setImmediate
setImmediate($uniqueId, $val)
Определения
managedcache.php:88
Bitrix\Main\Data\ManagedCache\__construct
__construct()
Определения
managedcache.php:24
Bitrix\Main\Data\ManagedCache\$vars
$vars
Определения
managedcache.php:20
Bitrix\Main\Data\ManagedCache\$cacheInit
$cacheInit
Определения
managedcache.php:18
Bitrix\Main\Data\ManagedCache\cleanAll
cleanAll()
Определения
managedcache.php:141
Bitrix\Main\Data\ManagedCache\finalize
static finalize()
Определения
managedcache.php:155
Bitrix\Main\Data\ManagedCache\getCompCachePath
getCompCachePath($relativePath)
Определения
managedcache.php:169
Bitrix\Main\Data\ManagedCache\$dbType
$dbType
Определения
managedcache.php:22
Bitrix\Main\Data\ManagedCache\$ttl
$ttl
Определения
managedcache.php:21
Bitrix\Main\Data\ManagedCache\$cachePath
$cachePath
Определения
managedcache.php:19
Bitrix\Main\Data\ManagedCache\cleanDir
cleanDir($tableId)
Определения
managedcache.php:123
Bitrix\Main\Data\ManagedCache\getImmediate
getImmediate($ttl, $uniqueId, $tableId=false)
Определения
managedcache.php:44
Bitrix\Main\Data\ManagedCache\$cache
$cache
Определения
managedcache.php:17
Bitrix\Main\Data\ManagedCache\read
read($ttl, $uniqueId, $tableId=false)
Определения
managedcache.php:32
Bitrix\Main
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$val
$val
Определения
options.php:1793
SITE_ID
const SITE_ID
Определения
sonet_set_content_view.php:12
bitrix
modules
main
lib
data
managedcache.php
Создано системой
1.14.0