Views: 10022
Last Modified: 22.09.2014


In case of a large database, a performance problem may occur due to the following reasons:

  • Access to this information array for read or write results in competitive requests;
  • The requests are fast in themselves, but there are so many of them that the database starts building a queue of them;
  • The requests are slow and complicated, and they are also very frequent.

Multilevel caching is used precisely to relieve the most loaded places in terms of resources and time. Each caching technique may be used for each component separately by choosing an optimal option for a specific case.

Note: Until the developer decides on the caching strategy and on what they want to obtain from it, a blind activation of caching might bring no visible results.

If we take an Internet store as an example, then for each item of goods a file in cache memory will be created so that the server will not have to send requests to the database in case of any future queries of the buyer.


Caching is a process technique that permits caching the outputs of rarely updated and resource-intensive parts of the code (for example, those actively working with the database).

Two classes of caching are created to implement this:

  • CPageCache - is a class for caching HTML result of script execution;
  • CPHPCache - is a class for caching PHP variables and HTML result of script execution.

The Bitrix Framework system includes different caching techniques:

  • Component caching (or Autocaching) – all dynamic components used to create web pages have an incorporated caching control support.

    In order to use this technique it is sufficient to turn on autocaching using a button on the administrative panel. In this case, all of the components with activated autocaching mode will create cache and switch to a work mode without database queries.

  • Uncontrolled caching is a possibility to set caching rules for resource-intensive parts of pages. Caching results are stored as files in the catalog /bitrix/cache/. If the caching time has not expired, instead of a resource-intensive code a preliminary created cache file will be connected.

    Caching is called uncontrolled because cache is not rebuilt automatically after the modification of source data, but operates during the specified time after creation, which is set in the Component parameters.

    The right use of caching permits to significantly increase the general performance of the site. However, it must be taken into account that an unreasonable use of caching may result in a serious increase of the /bitrix/cache/ catalog size.

  • Controlled cache automatically updates component cache in case of data change.
  • HTML cache should better be activated for a rarely changing section that is regularly visited by anonymous visitors. The technique is simple in operation, does not require that the user track changes, protects with a disc quota from data overload and autorecover operability in case the quota is exceeded or the data are changed.
  • Menu caching. A special algorithm is used for menu caching that takes into account the fact that the majority of visitors are unregistered visitors.

    Menu cache is controlled and updated during menu editing or a change of access rights to files and folders through an administrative interface and API.

Main caching settings are located on the page Caching settings (Control Panel > Settings > System settings > Cache Settings).

Note: In the D7 core, the caching settings are set in a special file.


An example of caching with the CPHPCache class:

$cntIBLOCK_List = 10;
$cache = new CPHPCache();
$cache_time = 3600;
$cache_id = 'arIBlockListID'.$cntIBLOCK_List;
$cache_path = '/arIBlockListID/';
if ($cache_time > 0 && $cache->InitCache($cache_time, $cache_id, $cache_path))
   $res = $cache->GetVars();
   if (is_array($res["arIBlockListID"]) && (count($res["arIBlockListID"]) > 0))
      $arIBlockListID = $res["arIBlockListID"];
if (!is_array($arIBlockListID))
   $res = CIBlock::GetList(
         'TYPE' => 'catalog', 
         'SITE_ID' => SITE_ID, 
         'ACTIVE' => 'Y', 
         "CNT_ACTIVE" => "Y", 
         "!CODE" => 'test%'
      ), true
   while($ar_res = $res->Fetch())
      if($ar_res['ELEMENT_CNT'] > 0)
      $arIBlockListID[] = $ar_res['ID'];
   //////////// end cache /////////
   if ($cache_time > 0)
         $cache->StartDataCache($cache_time, $cache_id, $cache_path);

Courses developed by Bitrix24