Beispiel #1
0
 public function initCache($TTL, $uniqueString, $initDir = false, $baseDir = "cache")
 {
     if ($initDir === false) {
         $request = Main\Context::getCurrent()->getRequest();
         $initDir = $request->getRequestedPageDirectory();
     }
     $personalRoot = Main\Application::getPersonalRoot();
     $this->baseDir = $personalRoot . "/" . $baseDir . "/";
     $this->initDir = $initDir;
     $this->filename = "/" . $this->getPath($uniqueString);
     $this->TTL = $TTL;
     $this->uniqueString = $uniqueString;
     $this->vars = false;
     if ($TTL <= 0) {
         return false;
     }
     if (static::shouldClearCache()) {
         return false;
     }
     $arAllVars = array("CONTENT" => "", "VARS" => "");
     if (!$this->cacheEngine->read($arAllVars, $this->baseDir, $this->initDir, $this->filename, $this->TTL)) {
         return false;
     }
     if (static::$showCacheStat) {
         $read = 0;
         $path = '';
         if ($this->cacheEngine instanceof ICacheEngineStat) {
             $read = $this->cacheEngine->getReadBytes();
             $path = $this->cacheEngine->getCachePath();
         } elseif ($this->cacheEngine instanceof \ICacheBackend) {
             /** @noinspection PhpUndefinedFieldInspection */
             $read = $this->cacheEngine->read;
             /** @noinspection PhpUndefinedFieldInspection */
             $path = $this->cacheEngine->path;
         }
         Diag\CacheTracker::addCacheStatBytes($read);
         Diag\CacheTracker::add($read, $path, $this->baseDir, $this->initDir, $this->filename, "R");
     }
     $this->content = $arAllVars["CONTENT"];
     $this->vars = $arAllVars["VARS"];
     return true;
 }
Beispiel #2
0
 function InitCache($TTL, $uniq_str, $initdir = false, $basedir = "cache")
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION, $USER;
     if ($initdir === false) {
         $initdir = $APPLICATION->GetCurDir();
     }
     $this->basedir = BX_PERSONAL_ROOT . "/" . $basedir . "/";
     $this->initdir = $initdir;
     $this->filename = "/" . CPHPCache::GetPath($uniq_str);
     $this->TTL = $TTL;
     $this->uniq_str = $uniq_str;
     $this->vars = false;
     if ($TTL <= 0) {
         return false;
     }
     if (isset($_GET["clear_cache_session"]) || isset($_GET["clear_cache"])) {
         if (is_object($USER) && $USER->CanDoOperation('cache_control')) {
             if (isset($_GET["clear_cache_session"])) {
                 if (strtoupper($_GET["clear_cache_session"]) == "Y") {
                     $_SESSION["SESS_CLEAR_CACHE"] = "Y";
                 } elseif (strlen($_GET["clear_cache_session"]) > 0) {
                     unset($_SESSION["SESS_CLEAR_CACHE"]);
                 }
             }
             if (isset($_GET["clear_cache"]) && strtoupper($_GET["clear_cache"]) == "Y") {
                 return false;
             }
         }
     }
     if (isset($_SESSION["SESS_CLEAR_CACHE"]) && $_SESSION["SESS_CLEAR_CACHE"] == "Y") {
         return false;
     }
     $arAllVars = array("CONTENT" => "", "VARS" => "");
     if (!$this->_cache->read($arAllVars, $this->basedir, $this->initdir, $this->filename, $this->TTL)) {
         return false;
     }
     $GLOBALS["CACHE_STAT_BYTES"] += $this->_cache->read;
     $this->content = $arAllVars["CONTENT"];
     $this->vars = $arAllVars["VARS"];
     return true;
 }