Good people, I ask for help! I decided to play around with component caching, since the performance test showed that they are not cached. 50-100 requests to the database when loading the page ...

Googling, it says everywhere that a component should contain files as standard:

.description.php .parameters.php component.php (без него якобы работать не будет) 

Useful to look at (the site developer is not me, but a freelancer)

My path to the component folder contains:

 Templates --.default --result_modifier.php --template.php class.php 

Please explain how I set up the component cache if there are no required files, but how does it work? I understand caching somehow here in the class.php file class.php need to register? Something similar about the cache has been recorded already!

Here is the code from this file.

 <?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); use Bitrix\Highloadblock as HL; use Bitrix\Main\Entity; use Itbiz\Project; class ItBizShowcaseMainMiddleSectionsList extends CBitrixComponent { public function executeComponent(){ global $USER; if ( !CModule::IncludeModule("iblock") ) return false; if ( !CModule::IncludeModule("highloadblock") ) return false; $brands = array(); $banners = array(); $sections = array(); $curIblock = (int)$_GET['iblock']; $arIblocks = Project\Showcase::getIblockList(); if ( $curIblock <= 0 ) $curIblock = P_IBLOCK_ID_PRODUCTS; elseif ( !array_key_exists($curIblock, $arIblocks) ) return; // Кэширование... $obCache = Project\Cache::getInstance(); $cacheParams = array($this->arParams); $cacheTag = array( 'iblock_id_' . $curIblock, 'region_'.$_SESSION['ITBIZ_USERPLACE']['REGION']['ID'] ); if ( !$obCache->init(__CLASS__.'/sections/', $cacheParams, $cacheTag) ) { $rs = CIBlockSection::GetList( array( 'DEPTH_LEVEL' => 'DESC', 'SORT' => 'ASC', 'ID' => 'ASC' ), array( 'ACTIVE' => 'Y', 'IBLOCK_ID' => $curIblock, '<=DEPTH_LEVEL' => 2, '!ID'=>3073, '!SECTION_ID'=>3073 ), true, array( 'ID', 'IBLOCK_SECTION_ID', 'NAME', 'SECTION_PAGE_URL', 'ELEMENT_CNT', 'UF_COLOR' ) ); while ( $rw = $rs->GetNext() ){ // Разкомментировать, если нужно // выводить секции только содержащие витрины // if ( $rw['ELEMENT_CNT'] <= 0 ) // continue; $tmp = array( 'id' => $rw['ID'], 'name' => $rw['NAME'], 'url' => $rw['SECTION_PAGE_URL'], 'color' => $rw['UF_COLOR'], 'items' => array() ); if ( isset($sections[$rw['ID']]) ) { $tmp['items'] = $sections[$rw['ID']]; unset($sections[$rw['ID']]); } $sections[(int)$rw['IBLOCK_SECTION_ID']][$rw['ID']] = $tmp; } $obCache->startDataCache($sections); }else{ $sections = $obCache->getVars(); } if ( empty($sections) ) return; $sections = array_shift($sections); //-------------------------------// Получим витрины для разделов...-------------------------------------------------------- $hlblock = HL\HighloadBlockTable::getById(19)->fetch(); $entityAdv = HL\HighloadBlockTable::compileEntity($hlblock); $hlblock = HL\HighloadBlockTable::getById(18)->fetch(); $entitySect = HL\HighloadBlockTable::compileEntity($hlblock); $arShowcase=array(); $propRegion = CIBlockProperty::GetList(Array("sort"=>"asc", "name"=>"asc"), Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$curIblock,"CODE"=>"REGIONS"))->fetch(); $propRegion=$propRegion['ID']; $propEntity=Project\ElementExTable::compilePropEntity($curIblock); foreach(array_keys($sections) as $section){ //if ( !$obCache->init(__CLASS__.'/'.$section.'/showcases/', $cacheParams, $cacheTag) ) { $query = new \Bitrix\Main\Entity\Query(Project\ElementExTable::getEntity()); $query ->registerRuntimeField("sectprice", array( "data_type" => $entitySect->getDataClass(), 'reference' => array('=this.ID' => 'ref.UF_SHOWCASE'), ) ) ->registerRuntimeField("advdata", array( "data_type" => $entityAdv->getDataClass(), 'reference' => array('=this.ID' => 'ref.UF_SHOWCASE'), 'join_type' => "INNER" ) ) ->registerRuntimeField("propdata", array( "data_type" => $propEntity->getDataClass(), 'reference' => array('=this.ID' => 'ref.IBLOCK_ELEMENT_ID'), 'join_type' => "INNER" ) ) ->setSelect(array( "ID", "NAME", 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'IBLOCK_SECTION_ID', 'IBLOCK_ID', 'advdata.UF_BALANCE' )) ->setFilter(array( "WF_STATUS_ID"=>1, "ACTIVE"=>"Y", "=sectprice.UF_ACTIVE"=>1, ">advdata.UF_BALANCE"=>0, "sectprice.UF_SECTION"=>$section, array( "LOGIC" => "OR", array(">ACTIVE_TO" => date("dmY H:i:s")), array("%ACTIVE_TO" => "") ), "propdata.IBLOCK_PROPERTY_ID"=>$propRegion, "propdata.VALUE"=>$_SESSION['ITBIZ_USERPLACE']['REGION']['ID'], )) ->setOrder(array("sectprice.UF_PRICE"=>"DESC")) ->setLimit(4); $result = $query->exec(); //PR($query->getLastQuery()); $result = new \CDBResult($result); $showcases=array(); while($rw=$result->fetch()){ $showcases[]=array( 'id' => $rw['ID'], 'name' => $rw['NAME'], 'url' => $rw['ITBIZ_PROJECT_ELEMENT_EX_advdata_UF_BALANCE']==666666?"/":"/".$rw['IBLOCK_ID']."/".$rw['ID']."/".$rw['IBLOCK_SECTION_ID']."/", 'img' => $rw['PREVIEW_PICTURE'], 'descr'=> $rw['PREVIEW_TEXT'], ); } /*$obCache->startDataCache($showcases); }else{ $showcases = $obCache->getVars(); }*/ $sections[$section]['showcase']=$showcases; //$arShowcase[$section]=$showcases; } //PR($arShowcase); //-------------------------------// Получим бренды для разделов...-------------------------------------------------------- if ( !$obCache->init(__CLASS__.'/elements/', $cacheParams, $cacheTag) ) { $rs=CIblockElement::getList(array(),array("IBLOCK_ID"=>$curIblock,"SECTION_ID"=>array_keys($sections),"INCLUDE_SUBSECTIONS"=>"Y","!PROPERTY_BRAND"=>false),array("IBLOCK_SECTION_ID","PROPERTY_BRAND"),false,array("ID","PROPERTY_BRAND","IBLOCK_SECTION_ID")); $brands=array(); $arSectBrands=array(); while($rw=$rs->fetch()){ $psect=$this->getParentSection($rw['IBLOCK_SECTION_ID'],$sections); if($psect>0){ if(array_search($rw['PROPERTY_BRAND_VALUE'],$arSectBrands[$psect])===false or !is_array($arSectBrands[$psect])) $arSectBrands[$psect][]=$rw['PROPERTY_BRAND_VALUE']; $brands = array_merge($brands, array_diff(array($rw['PROPERTY_BRAND_VALUE']), $brands)); } } $rs = Project\BrandsTable::getList(array( 'filter' => array('UF_XML_ID' => $brands), 'select' => array( 'name' => 'UF_NAME', 'code' => 'UF_XML_ID', 'img' => 'UF_FILE' ) )); $brands = array_flip($brands); while ( $rw = $rs->Fetch() ) $brands[$rw['code']] = array( 'name' => $rw['name'], 'code' => $rw['code'], 'img' => $rw['img'] ); $obCache->startDataCache(array( 'sectBrands' => $arSectBrands, 'brands' => $brands, )); }else{ $tmp = $obCache->getVars(); $arSectBrands = $tmp['sectBrands']; $brands = $tmp['brands']; unset($tmp); } foreach($arSectBrands as $sect=>$arBrands){ $sections[$sect]['brands']=$arBrands; } // ------------------ Баннеры для разделов -----------------------------------------------// $banners=array(); foreach (array_keys($sections) as $sectionID){ $rs = Project\Banner::getList(array( 'type_sid' => $curIblock == P_IBLOCK_ID_PRODUCTS?'MAIN_MIDDLE_SECTION':"SECTION_MID_BIG", 'showcase' => $sectionID, 'limit'=>1 ),array("CONTRACT"=>"DESC","SHOW_COUNT"=>"ASC","WEIGHT"=>"DESC")); foreach ( $rs as $v ) { $banners[$v['fields']['SHOWCASE']] = array( 'html' => $v['html'] ); } } $this->arResult = array( 'brands' => $brands, 'banners' => $banners, 'sections' => $sections ); $this->includeComponentTemplate(); } private function getParentSection($sectionID,$sections){ if(!array_key_exists($sectionID,$sections)){ foreach($sections as $key=>$sectArr){ if(array_key_exists($sectionID,$sectArr['items'])){ return $key; } } return false; }else{ return $sectionID; } } } 

I know where to enable caching in the component settings, but if there are no such settings, then where to register in the code and what to register to make the caching work?

    2 answers 2

    Judging by the component code, the caching is implemented not by using the methods of caching the components , but by using the Cache class of the core D7 bitrix. This approach eliminates the possibility of auto-caching (flushing the cache when records are changed in the information blocks), but query variables are still cached if the CACHE_TIME parameter is passed to the component call.

    It is necessary to find the call of the component and check this moment, the line looks like this:

     $APPLICATION->IncludeComponent( "название_комонента", "шаблон_компонента", array( //Параметры компонента... "CACHE_TIME" => 3600, //Время кеширования в секундах ) ) 

    If file caching is configured on the site and it is enabled on the site, folders and cache files should appear in the sections folder next to the file (the code is given above). Additional information on caching settings

      in the component settings add "CACHE_TIME" => 3600 this will display all the settings related to caching. Learn more: https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43&LESSON_ID=2132&LESSON_PATH=3913.4565.2132