1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
page_cache.php
См. документацию.
1<?php
2
9
14
16{
20 var $ttl;
21 var $bStarted = false;
22 var $uniq_str = false;
24 var $initdir = false;
25
26 function __construct()
27 {
28 $this->_cache = Cache::createCacheEngine();
29 }
30
32 {
33 $un = md5($uniq_str);
34 return mb_substr($un, 0, 2) . "/" . $un . ".html";
35 }
36
37 function Clean($uniq_str, $initdir = false, $basedir = "cache")
38 {
39 if (isset($this) && is_object($this) && is_object($this->_cache))
40 {
41 $basedir = BX_PERSONAL_ROOT . "/" . $basedir . "/";
43 if (Cache::getShowCacheStat())
44 {
45 CacheTracker::add(0, "", $basedir, $initdir, "/" . $filename, "C");
46 }
47 return $this->_cache->clean($basedir, $initdir, "/" . $filename);
48 }
49 else
50 {
51 $obCache = new CPageCache();
52 return $obCache->Clean($uniq_str, $initdir, $basedir);
53 }
54 }
55
56 function CleanDir($initdir = false, $basedir = "cache")
57 {
58 $basedir = BX_PERSONAL_ROOT . "/" . $basedir . "/";
59 if (Cache::getShowCacheStat())
60 {
61 CacheTracker::add(0, "", $basedir, $initdir, "", "C");
62 }
63
64 return $this->_cache->clean($basedir, $initdir);
65 }
66
67 function InitCache($TTL, $uniq_str, $initdir = false, $basedir = "cache")
68 {
70 global $APPLICATION, $USER;
71 if ($initdir === false)
72 {
73 $initdir = $APPLICATION->GetCurDir();
74 }
75
76 $this->basedir = BX_PERSONAL_ROOT . "/" . $basedir . "/";
77 $this->initdir = $initdir;
78 $this->filename = "/" . CPageCache::GetPath($uniq_str);
79 $this->ttl = $TTL;
80 $this->uniq_str = $uniq_str;
81
82 if ($TTL <= 0)
83 {
84 return false;
85 }
86
87 if (is_object($USER) && $USER->CanDoOperation('cache_control'))
88 {
89 if (isset($_GET["clear_cache_session"]))
90 {
91 if (strtoupper($_GET["clear_cache_session"]) == "Y")
92 {
93 Application::getInstance()->getKernelSession()["SESS_CLEAR_CACHE"] = "Y";
94 }
95 elseif (!empty($_GET["clear_cache_session"]))
96 {
97 unset(Application::getInstance()->getKernelSession()["SESS_CLEAR_CACHE"]);
98 }
99 }
100
101 if (isset($_GET["clear_cache"]) && strtoupper($_GET["clear_cache"]) == "Y")
102 {
103 return false;
104 }
105 }
106
107 if (
108 isset(Application::getInstance()->getKernelSession()["SESS_CLEAR_CACHE"])
109 && Application::getInstance()->getSession()["SESS_CLEAR_CACHE"] == "Y"
110 )
111 {
112 return false;
113 }
114
115 if (!$this->_cache->read($this->content, $this->basedir, $this->initdir, $this->filename, $this->ttl))
116 {
117 return false;
118 }
119
120 if (Cache::getShowCacheStat())
121 {
122 $read = 0;
123 $path = '';
124 if ($this->_cache instanceof CacheEngineStatInterface)
125 {
126 $read = $this->_cache->getReadBytes();
127 $path = $this->_cache->getCachePath();
128 }
129
131 CacheTracker::add($read, $path, $this->basedir, $this->initdir, $this->filename, "R");
132 }
133 return true;
134 }
135
136 function Output()
137 {
138 echo $this->content;
139 }
140
141 function StartDataCache($TTL, $uniq_str=false, $initdir=false, $basedir = "cache")
142 {
143 if ($this->InitCache($TTL, $uniq_str, $initdir, $basedir))
144 {
145 $this->Output();
146 return false;
147 }
148
149 if ($TTL<=0)
150 {
151 return true;
152 }
153
154 ob_start();
155 $this->bStarted = true;
156 return true;
157 }
158
159 function AbortDataCache()
160 {
161 if (!$this->bStarted)
162 {
163 return;
164 }
165
166 $this->bStarted = false;
167 ob_end_flush();
168 }
169
170 function EndDataCache()
171 {
172 if (!$this->bStarted)
173 {
174 return;
175 }
176
177 $this->bStarted = false;
178 $arAllVars = ob_get_contents();
179 $this->_cache->write($arAllVars, $this->basedir, $this->initdir, $this->filename, $this->ttl);
180
181 if (Cache::getShowCacheStat())
182 {
183 $written = 0;
184 $path = '';
185 if ($this->_cache instanceof CacheEngineStatInterface)
186 {
187 $written = $this->_cache->getWrittenBytes();
188 $path = $this->_cache->getCachePath();
189 }
190
192 CacheTracker::add($written, $path, $this->basedir, $this->initdir, $this->filename, "W");
193 }
194
195 if ($arAllVars <> '')
196 {
197 ob_end_flush();
198 }
199 else
200 {
201 ob_end_clean();
202 }
203 }
204
206 {
207 return $this->_cache->IsCacheExpired($path);
208 }
209}
$path
Определения access_edit.php:21
global $APPLICATION
Определения include.php:80
static getInstance()
Определения application.php:98
static addCacheStatBytes($cacheStatBytes)
Определения cachetracker.php:33
static add($size, $path, $baseDir, $initDir, $filename, $operation)
Определения cachetracker.php:43
Определения page_cache.php:16
$bStarted
Определения page_cache.php:21
$filename
Определения page_cache.php:18
__construct()
Определения page_cache.php:26
EndDataCache()
Определения page_cache.php:170
Clean($uniq_str, $initdir=false, $basedir="cache")
Определения page_cache.php:37
InitCache($TTL, $uniq_str, $initdir=false, $basedir="cache")
Определения page_cache.php:67
IsCacheExpired($path)
Определения page_cache.php:205
Output()
Определения page_cache.php:136
$content
Определения page_cache.php:19
$ttl
Определения page_cache.php:20
AbortDataCache()
Определения page_cache.php:159
$initdir
Определения page_cache.php:24
StartDataCache($TTL, $uniq_str=false, $initdir=false, $basedir="cache")
Определения page_cache.php:141
$uniq_str
Определения page_cache.php:22
$basedir
Определения page_cache.php:23
GetPath($uniq_str)
Определения page_cache.php:31
CleanDir($initdir=false, $basedir="cache")
Определения page_cache.php:56
$_cache
Определения page_cache.php:17
global $USER
Определения csv_new_run.php:40
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393