A
A
Andrey Bely2022-02-23 20:15:11
1C-Bitrix
Andrey Bely, 2022-02-23 20:15:11

Why is the cache not updated correctly in the cached area when calling the CIBlockSection::GetList method?

Good evening everyone.
What I have:
In the parameters, the cache lifetime is 30 seconds.

template.php

<pre>
  <? var_dump($arResult) ?>
  </pre>


component.php(CIBlockSection::GetList method):
if ($this->StartResultCache()) {
  if (!CModule::IncludeModule("iblock")) {
    $this->AbortResultCache();
    ShowError("IBLOCK_MODULE_NOT_INSTALLED");
    return false;
  }
  $arSort= array("SORT" => "ASC", "DATE_ACTIVE_FROM" => "DESC", "ID" => "DESC");
  $arFilter = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "ACTIVE_DATE" => "Y");
  $arSelect = array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "NAME", "DATE_ACTIVE_FROM", "DEPTH_LEVEL", "UF_MAIN_SECTION");

  $rsElement = CIBlockSection::GetList(false, $arFilter, false, $arSelect, false);

  while ($obElement = $rsElement->GetNext()) {
    $arResult["ITEMS"][] = $obElement;
  }
  $this->SetResultCacheKeys(array());
  $this->IncludeComponentTemplate();
}


component.php(CIBlockElement::GetList method):
if ($this->StartResultCache()) {
  if (!CModule::IncludeModule("iblock")) {
    $this->AbortResultCache();
    ShowError("IBLOCK_MODULE_NOT_INSTALLED");
    return false;
  }
  $arSort= array("SORT" => "ASC", "DATE_ACTIVE_FROM" => "DESC", "ID" => "DESC");
  $arFilter = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "ACTIVE_DATE" => "Y");
  $arSelect = array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM", "PREVIEW_TEXT", "PREVIEW_PICTURE");

  $rsElement = CIBlockElement::GetList($arSort, $arFilter, false, $arNavParams, $arSelect);

  while($obElement = $rsElement->GetNextElement()) {
    $arElement = $obElement->GetFields();
    $arResult["ITEMS"][] = $arElement;
  }
  $this->SetResultCacheKeys(array());
  $this->IncludeComponentTemplate();
}


What I do:
Now I'm studying the mechanism of caching and it just so happened that I started with caching on bitrix. I noticed such a thing that if I call the CIBlockSection::GetList method in the cached area and put the result of the selection into $arResult, then:
1. When the cache is cleared on the page, I get the result of the template.php selection;
2. When an infoblock element is changed, the cache is updated, but there is no selection result in template.php;
3. When the cache lifetime ends, I initiate a hit, but there is no fetch result in template.php;

If I use CIBlockElement::GetList in the caching area, then everything works fine:
1. When the infoblock element changes, the cache is updated, and the result of the selection goes to template.php;
2. When the cache lifetime ends, I initiate a hit, and the result of the fetch gets into template.php;

Question:
Is the problem in the CIBlockSection::GetList method itself or in my code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Bely, 2022-02-26
@just_guy95

As a result, the problem was not in CIBlockSection::GetList, but in CIBlockElement::GetList. For some reason, CIBlockElement::GetList was ignoring the access rules that are set in the infoblock settings. More details in the comments to the question (see above)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question