1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
page.php
См. документацию.
1<?php
2namespace Bitrix\Main\Composite;
3
4use Bitrix\Main\Composite\Data\CacheProvider;
5use Bitrix\Main\Composite\Debug\Logger;
6use Bitrix\Main\Composite\Internals\Model\PageTable;
7use Bitrix\Main\Composite\Internals\PageManager;
8
13class Page
14{
18 protected static $instance = null;
22 private $cacheKey = null;
26 private $canCache = true;
27
31 private $storage = null;
32
36 private $cacheProvider = null;
37
38 private $voting = true;
45 public function __construct($requestUri = null, $host = null, $privateKey = null)
46 {
47 if (func_num_args())
48 {
49 $cacheKey = static::convertUriToPath($requestUri, $host, $privateKey);
50 $this->init($cacheKey);
51 }
52 }
53
54 protected function init($cacheKey)
55 {
56 if (is_string($cacheKey) && mb_strlen($cacheKey))
57 {
58 $this->cacheKey = $cacheKey;
59 $this->storage = $this->getStaticHtmlStorage($this->cacheKey);
60 }
61 }
62
63 public static function createFromCacheKey($cacheKey)
64 {
65 $storage = new static();
66 $storage->init($cacheKey);
67
68 return $storage;
69 }
70
76 public static function getInstance()
77 {
78 if (!isset(static::$instance))
79 {
80 $cacheProvider = static::getCacheProvider();
81 $privateKey = $cacheProvider !== null ? $cacheProvider->getCachePrivateKey() : null;
82
83 static::$instance = new static(
84 Helper::getRequestUri(),
85 Helper::getHttpHost(),
86 Helper::getRealPrivateKey($privateKey)
87 );
88
89 if ($cacheProvider !== null)
90 {
91 static::$instance->setCacheProvider($cacheProvider);
92 }
93 }
94
95 return static::$instance;
96 }
97
103 public function getStorage()
104 {
105 return $this->storage;
106 }
107
109 {
110 $this->cacheProvider = $provider;
111 }
112
116 private static function getCacheProvider()
117 {
118 foreach (GetModuleEvents("main", "OnGetStaticCacheProvider", true) as $arEvent)
119 {
121 if (is_object($provider) && $provider instanceof CacheProvider)
122 {
123 return $provider;
124 }
125 }
126
127 return null;
128 }
129
130 /*
131 * Returns private cache key
132 */
133 public static function getPrivateKey()
134 {
135 $cacheProvider = static::getCacheProvider();
136 return $cacheProvider !== null ? $cacheProvider->getCachePrivateKey() : null;
137 }
138
146 public static function convertUriToPath($uri, $host = null, $privateKey = null)
147 {
148 return Helper::convertUriToPath($uri, $host, $privateKey);
149 }
150
155 public function getCacheKey()
156 {
157 return $this->cacheKey;
158 }
159
166 public function write($content, $md5)
167 {
168 if ($this->storage === null)
169 {
170 return false;
171 }
172
173 $cacheSize = $this->storage->getSize();
174 $written = $this->storage->write($content."<!--".$md5."-->", $md5);
175 if ($written !== false && $this->storage->shouldCountQuota())
176 {
177 $delta = $cacheSize !== false ? $written - $cacheSize : $written;
178 if ($delta !== 0)
179 {
180 Helper::updateCacheFileSize($delta);
181 }
182 }
183
184 return $written;
185 }
186
192 public function read()
193 {
194 if ($this->storage !== null)
195 {
196 return $this->storage->read();
197 }
198
199 return false;
200 }
201
207 public function delete()
208 {
209 if ($this->storage === null)
210 {
211 return false;
212 }
213
214 $deletedSize = $this->storage->delete();
215 if ($deletedSize !== false && $this->storage->shouldCountQuota())
216 {
217 Helper::updateCacheFileSize(-$deletedSize);
218 }
219
220 PageManager::deleteByCacheKey($this->cacheKey);
221
222 return $deletedSize;
223 }
224
229 public function deleteAll()
230 {
231 if ($this->storage === null)
232 {
233 return false;
234 }
235
236 $this->storage->deleteAll();
237
238 if ($this->storage->shouldCountQuota())
239 {
240 Helper::updateCacheFileSize(false);
241 }
242
243 PageTable::deleteAll();
244
245 return true;
246 }
247
252 public function getLastModified()
253 {
254 if ($this->storage !== null)
255 {
256 return $this->storage->getLastModified();
257 }
258
259 return false;
260 }
261
267 public function exists()
268 {
269 if ($this->storage !== null)
270 {
271 return $this->storage->exists();
272 }
273
274 return false;
275 }
276
281 public function getMd5()
282 {
283 if ($this->storage !== null)
284 {
285 return $this->storage->getMd5();
286 }
287
288 return false;
289 }
290
295 public function getSize()
296 {
297 if ($this->storage !== null)
298 {
299 return $this->storage->getSize();
300 }
301
302 return false;
303 }
304
310 public function isCacheable()
311 {
312 if ($this->storage === null)
313 {
314 return false;
315 }
316
317 if ($this->cacheProvider !== null && $this->cacheProvider->isCacheable() === false)
318 {
319 return false;
320 }
321
322 if (isset(\Bitrix\Main\Application::getInstance()->getKernelSession()["SESS_SHOW_TIME_EXEC"]) && (\Bitrix\Main\Application::getInstance()->getKernelSession()["SESS_SHOW_TIME_EXEC"] == 'Y'))
323 {
324 return false;
325 }
326 elseif (isset(\Bitrix\Main\Application::getInstance()->getKernelSession()["SHOW_SQL_STAT"]) && (\Bitrix\Main\Application::getInstance()->getKernelSession()["SHOW_SQL_STAT"] == 'Y'))
327 {
328 return false;
329 }
330 elseif (isset(\Bitrix\Main\Application::getInstance()->getKernelSession()["SHOW_CACHE_STAT"]) && (\Bitrix\Main\Application::getInstance()->getKernelSession()["SHOW_CACHE_STAT"] == 'Y'))
331 {
332 return false;
333 }
334
335 $httpStatus = intval(\CHTTP::GetLastStatus());
336 if ($httpStatus == 200 || $httpStatus === 0)
337 {
338 return $this->canCache;
339 }
340
341 return false;
342 }
343
349 public function markNonCacheable()
350 {
351 $this->canCache = false;
352
353 if (Logger::isOn())
354 {
355 $debugBacktrace = debug_backtrace();
356
357 Logger::log(array(
358 "TYPE" => Debug\Logger::TYPE_PAGE_NOT_CACHEABLE,
359 "MESSAGE" => "File: ".$debugBacktrace[0]["file"].":".$debugBacktrace[0]["line"]
360 ));
361 }
362 }
363
364 public function setUserPrivateKey()
365 {
366 if ($this->cacheProvider !== null)
367 {
368 $this->cacheProvider->setUserPrivateKey();
369 }
370 }
371
372 public function onBeforeEndBufferContent()
373 {
374 if ($this->cacheProvider !== null)
375 {
376 $this->cacheProvider->onBeforeEndBufferContent();
377 }
378 }
379
386 public static function getStaticHtmlStorage($cacheKey)
387 {
388 $configuration = array();
389 $htmlCacheOptions = Helper::getOptions();
390 $storage = $htmlCacheOptions["STORAGE"] ?? false;
391
392 if (in_array($storage, array("memcached", "memcached_cluster")))
393 {
394 if (extension_loaded("memcache"))
395 {
396 return new Data\MemcachedStorage($cacheKey, $configuration, $htmlCacheOptions);
397 }
398 else
399 {
400 return null;
401 }
402 }
403 else
404 {
405 return new Data\FileStorage($cacheKey, $configuration, $htmlCacheOptions);
406 }
407 }
408
409 public function enableVoting()
410 {
411 $this->voting = true;
412 }
413
414 public function disableVoting()
415 {
416 $this->voting = false;
417 }
418
419 public function isVotingEnabled()
420 {
421 return $this->voting;
422 }
423
430 {
431 if (
432 defined("USE_HTML_STATIC_CACHE")
433 && USE_HTML_STATIC_CACHE === true
434 && StaticArea::getCurrentDynamicId() === false //Voting doesn't work inside a dynamic area
435 )
436 {
437 if (!$this->isVotingEnabled())
438 {
439 return;
440 }
441
442 $this->canCache = false;
443
445 "TYPE" => Debug\Logger::TYPE_COMPONENT_VOTING,
446 "MESSAGE" => $context
447 ));
448 }
449 }
450}
451
452class_alias("Bitrix\\Main\\Composite\\Page", "Bitrix\\Main\\Data\\StaticHtmlCache");
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
static getInstance()
Определения application.php:98
static log(array $params=array())
Определения logger.php:61
disableVoting()
Определения page.php:414
enableVoting()
Определения page.php:409
getStorage()
Определения page.php:103
setUserPrivateKey()
Определения page.php:364
onBeforeEndBufferContent()
Определения page.php:372
read()
Определения page.php:192
static convertUriToPath($uri, $host=null, $privateKey=null)
Определения page.php:146
getSize()
Определения page.php:295
static createFromCacheKey($cacheKey)
Определения page.php:63
markNonCacheable()
Определения page.php:349
isCacheable()
Определения page.php:310
getMd5()
Определения page.php:281
write($content, $md5)
Определения page.php:166
__construct($requestUri=null, $host=null, $privateKey=null)
Определения page.php:45
setCacheProvider(CacheProvider $provider)
Определения page.php:108
getLastModified()
Определения page.php:252
isVotingEnabled()
Определения page.php:419
deleteAll()
Определения page.php:229
exists()
Определения page.php:267
static getInstance()
Определения page.php:76
static getPrivateKey()
Определения page.php:133
giveNegativeComponentVote($context="")
Определения page.php:429
static $instance
Определения page.php:18
getCacheKey()
Определения page.php:155
init($cacheKey)
Определения page.php:54
static getStaticHtmlStorage($cacheKey)
Определения page.php:386
static getCurrentDynamicId()
Определения staticarea.php:109
static GetLastStatus()
Определения http.php:486
$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
$context
Определения csv_new_setup.php:223
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$requestUri
Определения urlrewrite.php:51
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
Определения aliases.php:54
$host
Определения mysql_to_pgsql.php:32
$delta
Определения prolog_main_admin.php:363
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($decryptedData)) $storage
Определения quickway.php:270
$md5
Определения result_rec.php:12