diff --git a/CacheCIBlockElement.php b/CacheCIBlockElement.php new file mode 100644 index 0000000..3572127 --- /dev/null +++ b/CacheCIBlockElement.php @@ -0,0 +1,48 @@ + "ASC"], $arFilter = [], $arGroupBy = false, $arNavStartParams = false, $arSelectFields = []) + { + if (\CModule::IncludeModule("iblock")) { + $obCache = new \CPHPCache; + + // Время жизни кэша + $lifeTime = 60 * 10; + if (!empty($arFilter['IBLOCK_ID'])) { + $cacheID = $arFilter['IBLOCK_ID']; + } else { + $cacheID = "CacheCIBlockElementDefault"; + } + + if ($obCache->InitCache($lifeTime, $cacheID, "/")) { + $vars = $obCache->GetVars(); + $DbResult = $vars["RESULT_ARRAY"]; + } else { + $DbResult = \CIBlockElement::GetList($arOrder, $arFilter, $arGroupBy, $arNavStartParams, $arSelectFields); + } + if ($obCache->StartDataCache()) { + $obCache->EndDataCache([ + "RESULT_ARRAY" => $DbResult, + ]); + } + return $DbResult; + } + return false; + } + +} diff --git a/getLastNews.php b/getLastNews.php new file mode 100644 index 0000000..80d643a --- /dev/null +++ b/getLastNews.php @@ -0,0 +1,29 @@ +channel->item as $item) { + + if ($item->title) { + echo 'НАЗВАНИЕ: ' . $item->title . '
' . PHP_EOL; + } + + if ($item->link) { + echo 'ССЫЛКА НА НОВОСТЬ: ' . '' . $item->link . '
' . PHP_EOL; + } + + if ($item->description) { + echo 'АНОНС: ' . $item->description . '
' . PHP_EOL; + } + + echo '
'; + $count++; + + if ($count >= 5) { + break; + } +} diff --git a/test.php b/test.php new file mode 100644 index 0000000..c2cc0b0 --- /dev/null +++ b/test.php @@ -0,0 +1,14 @@ + 1, "ID" => '3', "ACTIVE_DATE" => "Y", "ACTIVE" => "Y"]; +if ($res = CacheClasses\CacheCIBlockElement::GetList([], $arFilter, false, ["nPageSize" => 50], $arSelect)) { + while ($arFields = $res->Fetch()) { + echo '
' . print_r($arFields, 1) . '
'; + } +} + +require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php");