Example #1
1
 public static function getPropertyFieldSections($linkIblockId)
 {
     $linkIblockId = (int) $linkIblockId;
     if ($linkIblockId <= 0) {
         return false;
     }
     $ttl = 10000;
     $cache_id = 'catalog_store_sections';
     $cache_dir = '/bx/catalog_store_sections';
     $obCache = new CPHPCache();
     if ($obCache->InitCache($ttl, $cache_id, $cache_dir)) {
         $res = $obCache->GetVars();
     } else {
         $res = array();
     }
     if (!isset($res[$linkIblockId])) {
         $res[$linkIblockId] = array();
         $sectionsIterator = Iblock\SectionTable::getList(array('select' => array('*'), 'filter' => array('=IBLOCK_ID' => $linkIblockId), 'order' => array('LEFT_MARGIN' => 'ASC')));
         while ($section = $sectionsIterator->fetch()) {
             $res[$linkIblockId][] = $section;
         }
         unset($section, $sectionsIterator);
         if ($obCache->StartDataCache()) {
             $obCache->EndDataCache($res);
         }
     }
     return $res[$linkIblockId];
 }
Example #2
0
File: CInc.php Project: Tvaruga/ae
 public static function getJobName($id)
 {
     if (empty($id)) {
         return false;
     }
     $result = false;
     $obCache = new CPHPCache();
     $dir = '/companies/names';
     if ($obCache->InitCache(9999999999, md5($id), $dir)) {
         $result = $obCache->GetVars();
     } elseif ($obCache->StartDataCache() && \Bitrix\Main\Loader::includeModule('iblock')) {
         if ($result = CIBlockElement::GetByID($id)->Fetch()) {
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $GLOBALS['CACHE_MANAGER']->StartTagCache($dir);
                 $GLOBALS['CACHE_MANAGER']->RegisterTag('iblock_id_' . $result['IBLOCK_ID']);
             }
             $result = $result['NAME'];
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $GLOBALS['CACHE_MANAGER']->EndTagCache();
             }
         }
         $obCache->EndDataCache($result);
     }
     return $result;
 }
Example #3
0
 function LoadTrigrams($dir_name)
 {
     if (empty($this->_trigrams)) {
         $file_name = $dir_name . "/trigram";
         if (file_exists($file_name) && is_file($file_name)) {
             $cache_id = filemtime($file_name) . "," . $file_name;
             $obCache = new CPHPCache();
             if ($obCache->StartDataCache(360000, $cache_id, "search")) {
                 $text = file_get_contents($file_name);
                 $ar = explode("\n", $text);
                 foreach ($ar as $trigramm) {
                     if (strlen($trigramm) == 3) {
                         $strScanCodesTmp = $this->ConvertToScancode($trigramm, false, true);
                         if (strlen($strScanCodesTmp) == 3) {
                             $this->_trigrams[$strScanCodesTmp] = true;
                         }
                     }
                 }
                 $obCache->EndDataCache($this->_trigrams);
             } else {
                 $this->_trigrams = $obCache->GetVars();
             }
         }
     }
 }
Example #4
0
 public function get($typeSID)
 {
     // ƒл¤ показа баннера одного типа только 1 раз на странице
     if (!empty($this->_typeSids[$typeSID])) {
         return false;
     }
     if (!empty($_SESSION['SESS_SHOW_INCLUDE_TIME_EXEC'])) {
         $debugKey = $_SESSION['SESS_SHOW_INCLUDE_TIME_EXEC'];
         $_SESSION["SESS_SHOW_INCLUDE_TIME_EXEC"] = 'N';
     }
     $cacheBlock = new CPHPCache();
     $url = CAdvBanner::GetCurUri();
     if (($pos = strpos(CAdvBanner::GetCurUri(), '?')) !== false) {
         $url = substr($url, 0, $pos);
     }
     $cacheId = $typeSID . '-' . $url;
     if ($cacheBlock->StartDataCache($this->_cacheTime, $cacheId, $this->_cacheDir)) {
         $result = CAdvBanner::Show($typeSID, '', '');
         $cacheBlock->EndDataCache(array('VARS' => $result));
     } else {
         $vars = $cacheBlock->GetVars();
         $result = $vars['VARS'];
     }
     if (!empty($_SESSION['SESS_SHOW_INCLUDE_TIME_EXEC'])) {
         $_SESSION['SESS_SHOW_INCLUDE_TIME_EXEC'] = $debugKey;
     }
     /*ѕодсчЄт показов*/
     if (empty($this->_typeSids[$typeSID])) {
         $this->_typeSids[$typeSID] = 1;
     } else {
         $this->_typeSids[$typeSID] = $this->_typeSids[$typeSID] + 1;
     }
     /**/
     return $result;
 }
Example #5
0
function getListElements( $arSort = array(), $arFilter = array(), $arNav = array(), $arGroup = array(), $arSelect = array(), $cache_id = '' ) {
	
	$cache = new CPHPCache();
	$cache_time = 3600;
	$cache_id = 'service_calc_'.$cache_id.'_'.md5(array( $arSort,$arFilter, $arNav, $arGroup, $arSelect, $cache_id));
	$cache_path = '/bitrix/cache/';

	if ($cache_time > 0 && $cache->InitCache($cache_time, $cache_id, $cache_path))
	{
	   $res = $cache->GetVars();
	   if (is_array($res["dbElements"]) && (!empty($res["dbElements"]) ) )
		  $dbElements = $res["dbElements"];
	}
	if (empty($dbElements))
	{
	   $dbElements = CIBlockElement::GetList ( $arSort,$arFilter, $arNav, $arGroup, $arSelect);
	   
	   //////////// end cache /////////
	   if ($cache_time > 0)
	   {
			 $cache->StartDataCache ( $cache_time, $cache_id, $cache_path);
			 $cache->EndDataCache   ( array("dbElements" => $dbElements) );
	   }
	}
	return $dbElements;
}
 /**
  * @param $userId
  * @return bool
  */
 public function canRead($userId)
 {
     if ($this->canRead !== null) {
         return $this->canRead;
     }
     if (!Loader::includeModule('socialnetwork')) {
         return false;
     }
     $cacheTtl = 2592000;
     $cacheId = 'blog_post_socnet_general_' . $this->entityId . '_' . LANGUAGE_ID;
     $timezoneOffset = \CTimeZone::getOffset();
     if ($timezoneOffset != 0) {
         $cacheId .= "_" . $timezoneOffset;
     }
     $cacheDir = '/blog/socnet_post/gen/' . intval($this->entityId / 100) . '/' . $this->entityId;
     $cache = new \CPHPCache();
     if ($cache->initCache($cacheTtl, $cacheId, $cacheDir)) {
         $post = $cache->getVars();
     } else {
         $cache->startDataCache();
         $queryPost = \CBlogPost::getList(array(), array("ID" => $this->entityId), false, false, array("ID", "BLOG_ID", "PUBLISH_STATUS", "TITLE", "AUTHOR_ID", "ENABLE_COMMENTS", "NUM_COMMENTS", "VIEWS", "CODE", "MICRO", "DETAIL_TEXT", "DATE_PUBLISH", "CATEGORY_ID", "HAS_SOCNET_ALL", "HAS_TAGS", "HAS_IMAGES", "HAS_PROPS", "HAS_COMMENT_IMAGES"));
         $post = $queryPost->fetch();
         $cache->endDataCache($post);
     }
     if (!$post) {
         $this->canRead = false;
         return false;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $this->canRead = \CBlogPost::getSocNetPostPerms($this->entityId, true, $userId, $post["AUTHOR_ID"]) >= BLOG_PERMS_READ;
     return $this->canRead;
 }
Example #7
0
 public static function sectionUFields($primary)
 {
     if (!$primary) {
         throw new ArgumentException('Не указан идентификатор инфоблока');
     }
     $cache = new \CPHPCache();
     $path = self::createPath(__METHOD__);
     $cacheId = md5($primary . $path);
     if ($cache->InitCache(86400 * 2, $cacheId, $path)) {
         $uFields = $cache->GetVars();
     } else {
         if (!is_numeric($primary)) {
             $iblock = self::iblock($primary);
             if (!$iblock) {
                 $cache->AbortDataCache();
                 return null;
             }
             $primary = $iblock['ID'];
         }
         global $USER_FIELD_MANAGER;
         $uFields = $USER_FIELD_MANAGER->getUserFields("IBLOCK_{$primary}_SECTION");
         if ($cache->StartDataCache()) {
             $cache->EndDataCache($uFields);
         }
     }
     return $uFields;
 }
 public static function SetRecent($entityId, $messageId, $isChat = false, $userId = false)
 {
     $entityId = intval($entityId);
     $messageId = intval($messageId);
     if ($entityId <= 0 || $messageId <= 0) {
         return false;
     }
     $userId = intval($userId);
     if ($userId <= 0) {
         $userId = $GLOBALS['USER']->GetID();
     }
     if (!$isChat && $userId == $entityId) {
         return false;
     }
     global $DB;
     $strSQL = "\n\t\t\tINSERT INTO b_im_recent (USER_ID, ITEM_TYPE, ITEM_ID, ITEM_MID)\n\t\t\tVALUES (" . $userId . ", '" . ($isChat ? IM_MESSAGE_GROUP : IM_MESSAGE_PRIVATE) . "', " . $entityId . ", " . $messageId . ")\n\t\t\tON DUPLICATE KEY UPDATE ITEM_MID = " . $messageId;
     $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $obCache = new CPHPCache();
     $obCache->CleanDir('/bx/im/rec' . CIMMessenger::GetCachePath($userId));
     if ($isChat) {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_GROUP);
     } else {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_MESSAGE);
     }
     return true;
 }
 public function addVariants(&$field, $params)
 {
     if (!$params["LINK_IBLOCK_ID"]) {
         return;
     }
     $cacheDir = KFilter::$config['CACHE_DIR'] . self::$cacheSubdir;
     $obCache = new CPHPCache();
     if ($obCache->InitCache(KFilter::$config['CACHE_TIME'], md5($params["LINK_IBLOCK_ID"] . __METHOD__), $cacheDir)) {
         $field['VARIANTS'] = $obCache->GetVars();
     } elseif ($obCache->StartDataCache()) {
         CModule::IncludeModule('iblock');
         global $CACHE_MANAGER;
         $CACHE_MANAGER->StartTagCache($cacheDir);
         $CACHE_MANAGER->RegisterTag("iblock_id_" . $params["LINK_IBLOCK_ID"]);
         $CACHE_MANAGER->EndTagCache();
         $rsSect = CIBlockSection::GetList(array('sort' => 'asc', 'name' => 'asc'), array('IBLOCK_ID' => $params["LINK_IBLOCK_ID"], 'ACTIVE' => 'Y'), false, array('ID', 'NAME'));
         while ($arSect = $rsSect->GetNext()) {
             $field['VARIANTS'][] = array('ID' => $arSect['ID'], 'NAME' => $arSect['NAME']);
         }
         $obCache->EndDataCache($field['VARIANTS']);
     }
     foreach ($field['VARIANTS'] as &$section) {
         if ($_REQUEST[$field['NAME']] == $section['ID']) {
             $section['SELECTED'] = 'Y';
             $res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $params["LINK_IBLOCK_ID"], "SECTION_ID" => $section['ID']), false, false, array("ID", "IBLOCK_ID"));
             $arr = array();
             while ($el = $res->GetNext()) {
                 $arr[] = $el['ID'];
             }
             $this->filter['PROPERTY_' . $field['PROPERTY']] = $arr;
             break;
         }
     }
 }
Example #10
0
 /**
  * @return bool true if some mandatory UF exists for TASKS
  */
 public static function isMandatoryUserFieldExists()
 {
     /** @var $CACHE_MANAGER CCacheManager */
     global $CACHE_MANAGER;
     $isFieldExists = null;
     // unknown yet
     $obCache = new CPHPCache();
     $lifeTime = CTasksTools::CACHE_TTL_UNLIM;
     $cacheID = md5('uftasks');
     $cacheDir = "/tasks/ufs";
     if (defined('BX_COMP_MANAGED_CACHE') && $obCache->InitCache($lifeTime, $cacheID, $cacheDir)) {
         $data = $obCache->GetVars();
         $isFieldExists = $data['isFieldExists'];
     } else {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $rsUserType = CUserTypeEntity::GetList(array(), array('ENTITY_ID' => 'TASKS_TASK', 'MANDATORY' => 'Y'));
         if ($rsUserType->fetch()) {
             $isFieldExists = true;
         } else {
             $isFieldExists = false;
         }
         if (defined('BX_COMP_MANAGED_CACHE') && $obCache->StartDataCache()) {
             $CACHE_MANAGER->StartTagCache($cacheDir);
             $CACHE_MANAGER->RegisterTag('tasks_user_fields');
             $CACHE_MANAGER->EndTagCache();
             $data = array('isFieldExists' => $isFieldExists);
             $obCache->EndDataCache($data);
         }
     }
     return $isFieldExists;
 }
Example #11
0
 public static function getPropertyFieldSections($linkIblockId)
 {
     $linkIblockId = (int) $linkIblockId;
     if ($linkIblockId <= 0) {
         return false;
     }
     $ttl = 10000;
     $cache_id = 'catalog_store_sections';
     $cache_dir = '/bx/catalog_store_sections';
     $obCache = new CPHPCache();
     if ($obCache->InitCache($ttl, $cache_id, $cache_dir)) {
         $res = $obCache->GetVars();
     } else {
         $res = array();
     }
     if (!isset($res[$linkIblockId])) {
         $res[$linkIblockId] = array();
         $sections = \CIBlockSection::GetTreeList(array("IBLOCK_ID" => $linkIblockId));
         while ($row = $sections->Fetch()) {
             $res[$linkIblockId][] = $row;
         }
         if ($obCache->StartDataCache()) {
             $obCache->EndDataCache($res);
         }
     }
     return $res[$linkIblockId];
 }
		function __blogcleartagsimportant($options, $cache_id, $cache_path)
		{
			$obCache = new CPHPCache;
			if ($cache_id != "")
				$obCache->Clean($cache_id, $cache_path);
			else
				$obCache->CleanDir($cache_path);
		}
Example #13
0
 /**
  * @param $name
  * @param $value
  * @param int $time
  */
 public function set($name, $value, $time = 3600)
 {
     $cache = new \CPHPCache();
     list($dir, $name) = $this->dirAndName($name);
     $cache->InitCache($time, $name, $dir);
     $cache->Clean($name, $dir);
     $cache->StartDataCache();
     $cache->EndDataCache(array('value' => $value));
 }
Example #14
0
 protected function parsePath($requestUri)
 {
     static $storages;
     if (empty($storages)) {
         $cache = new \CPHPCache();
         if ($cache->initCache(30 * 24 * 3600, 'webdav_disk_common_storage', '/webdav/storage')) {
             $storages = $cache->getVars();
         } else {
             $storages = \Bitrix\Disk\Storage::getModelList(array('filter' => array('=ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className())));
             foreach ($storages as $key => $storage) {
                 $storages[$key] = array('id' => $storage->getEntityId(), 'path' => $storage->getProxyType()->getStorageBaseUrl());
             }
             $cache->startDataCache();
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
                 $taggedCache->startTagCache('/webdav/storage');
                 $taggedCache->registerTag('disk_common_storage');
                 $taggedCache->endTagCache();
             }
             $cache->endDataCache($storages);
         }
     }
     $patterns = array(array('user', '/(?:company|contacts)/personal/user/(\\d+)/files/lib(.*)$'), array('user', '/(?:company|contacts)/personal/user/(\\d+)/disk/path(.*)$'), array('group', '/workgroups/group/(\\d+)/files(.*)$'), array('group', '/workgroups/group/(\\d+)/disk/path(.*)$'));
     foreach ($storages as $storage) {
         $storagePath = trim($storage['path'], '/');
         $patterns[] = array('docs', sprintf('^/%s/path(.*)$', $storagePath), $storage['id']);
         $patterns[] = array('docs', sprintf('^/%s(.*)$', $storagePath), $storage['id']);
     }
     // @TODO: aggregator
     $patterns[] = array('docs', '^/docs/path(.*)$', 'shared_files_s1');
     $patterns[] = array('docs', '^/docs(.*)$', 'shared_files_s1');
     $type = null;
     $id = null;
     $path = null;
     foreach ($patterns as $pattern) {
         $matches = array();
         if (preg_match('#' . $pattern[1] . '#i', $requestUri, $matches)) {
             $type = $pattern[0];
             list($id, $path) = $type == 'docs' ? array($pattern[2], $matches[1]) : array($matches[1], $matches[2]);
             break;
         }
     }
     /** @var Storage $storage */
     $storage = null;
     if ($type == 'user') {
         $storage = Driver::getInstance()->getStorageByUserId((int) $id);
     } elseif ($type == 'group') {
         $storage = Driver::getInstance()->getStorageByGroupId((int) $id);
     } elseif ($type == 'docs') {
         $storage = Driver::getInstance()->getStorageByCommonId($id);
     } else {
         return array(null, null);
     }
     $path = static::UrlDecode($path);
     return array($storage, $path);
 }
Example #15
0
 public static function getData($SITE_ID = SITE_ID, $bFull = false)
 {
     global $USER, $CACHE_MANAGER;
     $obCache = new CPHPCache();
     $today = ConvertTimeStamp();
     $cache_dir = '/intranet/planner/' . $USER->GetID();
     $cache_id = 'intranet|planner|' . $USER->GetID() . '|' . $SITE_ID . '|' . intval($bFull) . '|' . $today . '|' . FORMAT_DATETIME . '|' . FORMAT_DATE . '|' . LANGUAGE_ID;
     $arData = null;
     if ($obCache->InitCache(self::CACHE_TTL, $cache_id, $cache_dir)) {
         $arData = $obCache->GetVars();
         if (is_array($arData['SCRIPTS'])) {
             foreach ($arData['SCRIPTS'] as $key => $script) {
                 if (is_array($script)) {
                     $arData['SCRIPTS'][$key] = self::JS_CORE_EXT_RANDOM_NAME . RandString(5);
                     CJSCore::RegisterExt($arData['SCRIPTS'][$key], $script);
                 }
             }
         }
     } else {
         // cache expired or there's no cache
         $obCache->StartDataCache();
         $arData = array('SCRIPTS' => array(), 'STYLES' => array(), 'DATA' => array());
         $CACHE_MANAGER->StartTagCache($cache_dir);
         $CACHE_MANAGER->RegisterTag(self::CACHE_TAG . $USER->GetID());
         $events = GetModuleEvents("intranet", "OnPlannerInit");
         while ($arEvent = $events->Fetch()) {
             $arEventData = ExecuteModuleEventEx($arEvent, array(array('SITE_ID' => SITE_ID, 'FULL' => $bFull)));
             if (is_array($arEventData)) {
                 if (is_array($arEventData['SCRIPTS'])) {
                     $arData['SCRIPTS'] = array_merge($arData['SCRIPTS'], $arEventData['SCRIPTS']);
                 }
                 if (is_array($arEventData['STYLES'])) {
                     $arData['STYLES'] = array_merge($arData['STYLES'], $arEventData['STYLES']);
                 }
                 if (is_array($arEventData['DATA'])) {
                     $arData['DATA'] = array_merge($arData['DATA'], $arEventData['DATA']);
                 }
             }
         }
         $arCacheData = $arData;
         if (is_array($arCacheData['SCRIPTS'])) {
             foreach ($arCacheData['SCRIPTS'] as $key => $script) {
                 if (CJSCore::IsExtRegistered($script)) {
                     $arCacheData['SCRIPTS'][$key] = CJSCore::getExtInfo($script);
                 }
             }
         }
         $CACHE_MANAGER->EndTagCache();
         $obCache->EndDataCache($arCacheData);
     }
     return $arData;
 }
Example #16
0
function CheckCacheFiles_Rec($strDir)
{
	global $iGoodNum, $iOldNum, $iEmptyDirNum, $dLog;

	if ($handle = @opendir($strDir))
	{
		while (($file = readdir($handle)) !== false)
		{
			if ($file == "." || $file == "..") continue;

			if (is_dir($strDir."/".$file))
			{
				CheckCacheFiles_Rec($strDir."/".$file);
			}
			elseif (is_file($strDir."/".$file))
			{
				$ext = "";
				$ext_pos = bxstrrpos($file, ".");
				if ($ext_pos!==false)
					$ext = substr($file, $ext_pos + 1);

				$bCacheExp = False;
				if ($ext=="html")
					$bCacheExp = CPageCache::IsCacheExpired($strDir."/".$file);
				elseif ($ext=="php")
					$bCacheExp = CPHPCache::IsCacheExpired($strDir."/".$file);

				if ($bCacheExp)
				{
					$iOldNum++;
					@unlink($strDir."/".$file);
				}
				else
				{
					$iGoodNum++;
				}
			}
		}
		@closedir($handle);
	}

	clearstatcache();

	$bEmptyFolder = True;
	if ($handle = @opendir($strDir))
	{
		while (($file = readdir($handle)) !== false)
		{
			if ($file == "." || $file == "..") continue;
			$bEmptyFolder = False;
			break;
		}
	}

	if ($bEmptyFolder)
	{
		$iEmptyDirNum++;
		@rmdir($strDir);
	}
}
Example #17
0
 /**
  * Set mutable attributes
  * @param bool   $bFromCache
  * @param string $strUserIds
  */
 protected function workWithNonCacheAttr($bFromCache = false, $strUserIds = '')
 {
     //if list of users in cache - get last activity
     if ($bFromCache && $strUserIds) {
         $dbRes = CUser::getList($by = 'id', $order = 'asc', array('ID' => $strUserIds, 'LAST_ACTIVITY' => static::LAST_ACTIVITY), array('FIELDS' => array('ID')));
         while ($arRes = $dbRes->fetch()) {
             if ($this->arResult['USERS'][$arRes['ID']]) {
                 $this->arResult['USERS'][$arRes['ID']]['IS_ONLINE'] = true;
             }
         }
         unset($dbRes, $arRes);
     }
     $buildResizedPhoto = false;
     $displayPhoto = $this->displayPersonalPhoto();
     foreach ($this->arResult['USERS'] as &$arUser) {
         if ($this->bExcel && $displayPhoto) {
             //if export in excel, then method $this->resizePersonalPhoto() not run. And not modify PERSONAL_PHOTO
             if (!$arUser['PERSONAL_PHOTO']) {
                 $arUser['PERSONAL_PHOTO'] = $this->getDefaultPictureSonet($arUser['PERSONAL_GENDER']);
             }
             $arUser['PERSONAL_PHOTO_SOURCE'] = $arUser['PERSONAL_PHOTO'];
             $arUser['PERSONAL_PHOTO'] = CFile::GetPath($arUser['PERSONAL_PHOTO']);
         } elseif ($bFromCache && $displayPhoto) {
             $buildResizedPhoto = $this->resizePersonalPhoto($arUser) || $buildResizedPhoto;
         }
         $arUser['IS_BIRTHDAY'] = CIntranetUtils::IsToday($arUser['PERSONAL_BIRTHDAY']);
         $arUser['IS_ABSENT'] = CIntranetUtils::IsUserAbsent($arUser['ID']);
     }
     //rewrite cache if we build new resized photo
     if ($buildResizedPhoto) {
         $this->obCache->clean($this->cacheId, $this->cacheDir);
         $this->obCache->startDataCache();
         $this->obCache->endDataCache(array('USERS' => $this->arResult['USERS'], 'STR_USER_ID' => $strUserIds, 'DEPARTMENTS' => $this->arResult['DEPARTMENTS'], 'DEPARTMENT_HEAD' => $this->arResult['DEPARTMENT_HEAD'], 'USERS_NAV' => $this->arResult['USERS_NAV']));
     }
 }
Example #18
0
function getSections()
{
    CModule::IncludeModule("iblock");
    $obCache = new CPHPCache();
    $lifeTime = 60 * 60 * 2;
    $cacheId = 'u_creative_sections';
    $data = array();
    $arFilter = array('IBLOCK_ID' => IBLOCK_ID);
    $raw = CIBlockSection::GetList(array('ID' => 'ASC'), $arFilter);
    while ($item = $raw->Fetch()) {
        $data[$item['CODE']] = $item['ID'];
    }
    $obCache->StartDataCache($lifeTime, $cacheId, "/");
    $obCache->EndDataCache(array("SECTIONS" => $data));
    return $data;
}
Example #19
0
 public function loadConfig()
 {
     //todo fix empty config caching
     $cache = new \CPHPCache();
     $cacheFile = $_SERVER['DOCUMENT_ROOT'] . "/bitrix/cache/" . $cache->GetPath(__CLASS__);
     // проверяем, обновлялся ли конфиг
     $cacheWritten = filemtime($cacheFile);
     $configWritten = filemtime($this->configFile);
     // устаревший кеш или неудачно начатый кеш перезаписываем
     if ($configWritten > $cacheWritten || !$cache->InitCache(self::TTL, __CLASS__, '/')) {
         $cache->Clean(__CLASS__, '/');
         try {
             parent::loadConfig();
             if ($cache->StartDataCache(self::TTL, __CLASS__, '/')) {
                 $cache->EndDataCache(array('config' => $this->config));
             } else {
                 _log('Caching failed', 'widgets');
             }
         } catch (Exception $e) {
             _log('loading config error: ' . $e->getMessage(), 'widgets');
         }
     } else {
         $vars = $cache->GetVars();
         $this->config = $vars['config'];
     }
 }
 public static function GetData($courseId)
 {
     $arContents = array();
     $cacheId = 'course_id_' . (string) (int) $courseId;
     $oCache = new CPHPCache();
     if ($oCache->InitCache(self::TTL, $cacheId, self::CACHE_PATH) && !self::IsDirty()) {
         $arCached = $oCache->GetVars();
         if (isset($arCached['arContents']) && is_array($arCached['arContents'])) {
             $arContents = $arCached['arContents'];
         }
     } else {
         self::Purge();
         $arContents = self::GetDataWoCache($courseId);
         $oCache->StartDataCache(self::TTL, $cacheId, self::CACHE_PATH);
         $oCache->EndDataCache(array('arContents' => $arContents));
         self::MarkAsClean();
     }
     return $arContents;
 }
Example #21
0
 public static function getValueFromCache($cache_function, $cache_function_params, $nocache = false)
 {
     $result = null;
     $obj_cache = new CPHPCache();
     $cache_time = self::DEFAULT_CACHE_PERIOD;
     $cache_id = $cache_function . serialize($cache_function_params);
     $cache_path = '/drclinics/' . $cache_function . '/';
     if (!$nocache && $obj_cache->InitCache($cache_time, $cache_id, $cache_path)) {
         $result = $obj_cache->GetVars();
     } else {
         if ($nocache || $obj_cache->StartDataCache($cache_time, $cache_id, $cache_path)) {
             $result = call_user_func_array(__CLASS__ . '::' . $cache_function, $cache_function_params);
             if (!$nocache) {
                 $obj_cache->EndDataCache($result);
             }
         }
     }
     return $result;
 }
Example #22
0
 public function getObject($id, $code, $sectionCode = false, $iblock = false, $clear_cache = "N")
 {
     $id = (int) $id;
     $cache = new CPHPCache();
     if ($id) {
         $arFilter = array("ID" => $id);
         $cacheId = "object_" . $id . $sectionCode;
         $cachePath = "/" . SITE_ID . "/object/" . substr($id, 0, 3);
     } else {
         $arFilter = array("=CODE" => $code);
         $cacheId = "object_" . $code . $sectionCode;
         $cachePath = "/" . SITE_ID . "/object/" . substr($code, 0, 3);
     }
     if ($sectionCode) {
         $arFilter["SECTION_CODE"] = $sectionCode;
         $arFilter["!SECTION_ID"] = false;
     }
     if ($iblock) {
         $arFilter["IBLOCK_ID"] = $iblock;
     }
     // чистим кеш?
     if ('Y' == $clear_cache) {
         CPHPCache::clean($cacheId, $cachePath);
     }
     $cacheTime = CACHE_OBJECT;
     if ($cache->InitCache($cacheTime, $cacheId, $cachePath)) {
         $vars = $cache->GetVars();
         $obj = $vars["OBJECT"];
         return $obj;
     } else {
         $res = CIBlockElement::GetList(array(), $arFilter);
         if ($elem = $res->GetNextElement()) {
             $obj = $elem->GetFields();
             $props = $elem->GetProperties();
             $obj["PROPS"] = $props;
             if ($cache->StartDataCache()) {
                 $cache->EndDataCache(array("OBJECT" => $obj));
             }
             return $obj;
         }
     }
     return null;
 }
 private function __construct()
 {
     $cache = new CPHPCache();
     $cache_time = 2592000;
     // month
     $cache_id = self::$cacheKey;
     $cache_path = '/' . self::$cacheKey . '/';
     if ($cache->InitCache($cache_time, $cache_id, $cache_path)) {
         $vars = $cache->GetVars();
         $this->arIBlockIds = $vars['arIBlockIds'];
         $this->arPropertyIds = $vars['arPropertyIds'];
         $this->arPropertyValueIds = $vars['arPropertyValueIds'];
     } else {
         $cache->StartDataCache($cache_time, $cache_id, $cache_path);
         $this->SetIBlocks();
         $this->SetProperties();
         $cache->EndDataCache(array('arIBlockIds' => $this->arIBlockIds, 'arPropertyIds' => $this->arPropertyIds, 'arPropertyValueIds' => $this->arPropertyValueIds));
     }
 }
Example #24
0
 /**
  * Get active channels by city
  * 
  * @return array
  */
 public static function getActiveByCity()
 {
     $arChannels = array();
     $arFilter = array("=UF_CHANNEL.UF_BASE.UF_ACTIVE" => 1, "=UF_CITY_ID" => $_SESSION["USER_GEO"]["ID"]);
     $arSelect = array('ID', 'UF_CHANNEL_ID', 'UF_CHANNEL_BASE_ID' => 'UF_CHANNEL.UF_BASE.ID', 'UF_TITLE' => 'UF_CHANNEL.UF_BASE.UF_TITLE', 'UF_ICON' => 'UF_CHANNEL.UF_BASE.UF_ICON', 'UF_CODE' => 'UF_CHANNEL.UF_BASE.UF_CODE', "UF_IS_NEWS" => 'UF_CHANNEL.UF_BASE.UF_IS_NEWS', 'UF_PRICE' => 'UF_CHANNEL.UF_BASE.UF_PRICE_H24');
     $arSort = array("UF_CHANNEL.UF_BASE.UF_SORT" => "ASC");
     $obCache = new \CPHPCache();
     if ($obCache->InitCache(86400, serialize($arFilter) . serialize($arSelect) . serialize($arSort), "/channels_active/")) {
         $arChannels = $obCache->GetVars();
     } elseif ($obCache->StartDataCache()) {
         $result = \Hawkart\Megatv\ChannelCityTable::getList(array('filter' => $arFilter, 'select' => $arSelect, 'order' => $arSort));
         while ($row = $result->fetch()) {
             $row["ID"] = $row["UF_CHANNEL_ID"];
             $row["DETAIL_PAGE_URL"] = "/channels/" . $row['UF_CODE'] . "/";
             $arChannels[] = $row;
         }
         $obCache->EndDataCache($arChannels);
     }
     return $arChannels;
 }
Example #25
0
 /**
  * Ищет данные о сущности по ее названию
  * @param string $name
  * @return array
  */
 public static function getEntityByName($name)
 {
     if (empty(self::$_entities[$name]) || !array_key_exists($name, self::$_entities[$name])) {
         $cid = 'bxar\\helpers\\HlEntity_' . $name;
         $obCache = new \CPHPCache();
         if ($obCache->InitCache(7200, $cid, '/')) {
             self::$_entities[$name] = $obCache->GetVars();
         } elseif ($obCache->StartDataCache()) {
             $filter = ['select' => ['ID', 'NAME', 'TABLE_NAME'], 'filter' => ['NAME' => $name]];
             $hlblock = \Bitrix\Highloadblock\HighloadBlockTable::getList($filter)->fetch();
             if (!empty($hlblock['ID'])) {
                 self::$_entities[$name] = $hlblock;
             } else {
                 self::$_entities[$name] = null;
             }
             $obCache->EndDataCache(self::$_entities[$name]);
         }
     }
     return self::$_entities[$name];
 }
Example #26
0
 function GetDefaultValue($user_id)
 {
     if (intval($user_id) <= 0) {
         return false;
     }
     global $CACHE_MANAGER;
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $ttl = 2592000;
     } else {
         $ttl = 600;
     }
     $cache_id = 'sonet_smartfilter_default_' . $user_id;
     $obCache = new CPHPCache();
     $cache_dir = '/sonet/log_smartfilter/';
     if ($obCache->InitCache($ttl, $cache_id, $cache_dir)) {
         $tmpVal = $obCache->GetVars();
         $default_value = $tmpVal["VALUE"];
         unset($tmpVal);
     } else {
         $default_value = false;
         if (is_object($obCache)) {
             $obCache->StartDataCache($ttl, $cache_id, $cache_dir);
         }
         $rsSmartFilter = CSocNetLogSmartFilter::GetList(array(), array("USER_ID" => $user_id), array("TYPE"));
         if ($arSmartFilter = $rsSmartFilter->Fetch()) {
             $default_value = $arSmartFilter["TYPE"];
         }
         if (is_object($obCache)) {
             $arCacheData = array("VALUE" => $default_value);
             $obCache->EndDataCache($arCacheData);
         }
     }
     unset($obCache);
     if (!$default_value) {
         $default_value = COption::GetOptionString("socialnetwork", "sonet_log_smart_filter", "N", "");
     }
     return $default_value;
 }
Example #27
0
 public static function SetRecent($arParams)
 {
     $itemId = intval($arParams['ENTITY_ID']);
     $messageId = intval($arParams['MESSAGE_ID']);
     if ($itemId <= 0) {
         return false;
     }
     $userId = intval($arParams['USER_ID']);
     if ($userId <= 0) {
         $userId = (int) $GLOBALS['USER']->GetID();
     }
     $chatType = IM_MESSAGE_PRIVATE;
     if (isset($arParams['CHAT_TYPE']) && in_array($arParams['CHAT_TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT))) {
         $chatType = $arParams['CHAT_TYPE'];
     } else {
         if (isset($arParams['CHAT_ID'])) {
             $orm = IM\ChatTable::getById($arParams['CHAT_ID']);
             if ($chatData = $orm->fetch()) {
                 $chatType = $chatData['TYPE'];
             }
         }
     }
     $isChat = in_array($chatType, array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT));
     if (!$isChat && $userId == $itemId) {
         return false;
     }
     global $DB;
     $strSQL = "\n\t\t\tINSERT INTO b_im_recent (USER_ID, ITEM_TYPE, ITEM_ID, ITEM_MID)\n\t\t\tVALUES (" . $userId . ", '" . $chatType . "', " . $itemId . ", " . $messageId . ")\n\t\t\tON DUPLICATE KEY UPDATE ITEM_MID = " . $messageId . "\n\t\t";
     $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     $obCache = new CPHPCache();
     $obCache->CleanDir('/bx/imc/recent' . CIMMessenger::GetCachePath($userId));
     if ($isChat) {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_GROUP);
     } else {
         CIMMessenger::SpeedFileDelete($userId, IM_SPEED_MESSAGE);
     }
     return true;
 }
Example #28
0
function IBlockElementsMenu($IBLOCK_ID)
{
    $obCache = new CPHPCache();
    $cacheLifetime = 86400;
    $cacheID = 'IBlockElementsMenu_' . $IBLOCK_ID;
    $cachePath = '/' . $cacheID;
    if ($obCache->InitCache($cacheLifetime, $cacheID, $cachePath)) {
        $vars = $obCache->GetVars();
        return $vars['NAV'];
    } elseif ($obCache->StartDataCache()) {
        CModule::IncludeModule("iblock");
        $arNav = array();
        $arSort = array("NAME" => "DESC");
        $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, 'ACTIVE' => 'Y');
        $rs = CIBlockElement::GetList($arSort, $arFilter, false, false);
        //$rs->SetUrlTemplates("/catalog/#SECTION_CODE#/#ELEMENT_CODE#.php");
        while ($item = $rs->GetNext()) {
            $arNav[] = array($item['NAME'], $item['DETAIL_PAGE_URL'], array(), array(), "");
        }
        $obCache->EndDataCache(array('NAV' => $arNav));
        return $arNav;
    }
}
Example #29
0
	/**
	 * Получение идентификатора информационного блока по его коду
	 * для нормальной работы необходимо чтобы у информационных блоков были уникальные коды
	 * 
	 * @param string $CODE - код иформационного блока
	 * @param string $TYPE_ID - тип информационных блоков в котором будет выполнятся поиск, необязательное по умолчани false - все типы
	 */
	public static function GetIBlockIdByCode($CODE, $TYPE_ID = false)
	{
		static $arCache;
		
		$CACHE_ID = "iblock";
		if($TYPE_ID)
			$CACHE_ID .= $TYPE_ID;

		if(isset($arCache[$CACHE_ID][$CODE]))
			return $arCache[$CACHE_ID][$CODE];
				
		if(!$CODE || !CModule::IncludeModule("iblock"))
			return false;
			
		$cache = new CPHPCache;
		if($cache -> StartDataCache(self::$CACHE_TIME, $CACHE_ID, self::$CACHE_DIR . '/' . SITE_ID))
		{
			$arIds = array();
			$arFilter = array("ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y");
			if($TYPE_ID)
				$arFilter["TYPE"] = $TYPE_ID;
				
			$rsIBlock = CIBlock::GetList(array(), $arFilter);
			while($arr = $rsIBlock -> Fetch())
				$arIds[$arr["CODE"]] = $arr["ID"];
				
			$cache -> EndDataCache(array("arIds" => $arIds));
		} else 
			extract($cache -> GetVars());
		
		$arCache[$CACHE_ID] = $arIds;
			
		if(isset($arIds[$CODE]))
			return $arIds[$CODE];
			
		return false;
	}
Example #30
0
 static function Add($arFields)
 {
     global $DB;
     if (!self::CheckFields('ADD', $arFields)) {
         return false;
     }
     $arInsert = $DB->PrepareInsert("b_socialservices_user", $arFields);
     $strSql = "INSERT INTO b_socialservices_user (" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
     $res = $DB->Query($strSql, true, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!$res) {
         $_SESSION["LAST_ERROR"] = GetMessage("SC_ADD_ERROR");
         return false;
     }
     $lastId = intval($DB->LastID());
     $cache_id = 'socserv_ar_user';
     $obCache = new CPHPCache();
     $cache_dir = '/bx/socserv_ar_user';
     $obCache->Clean($cache_id, $cache_dir);
     $events = GetModuleEvents("socialservices", "OnAfterSocServUserAdd");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     return $lastId;
 }