Views: 8726
Last Modified: 18.09.2014

Auto cache mode (Components cache) appeared in version 6 of the product replacing the standard component cache. The difference is that auto cache may be globally deactivated for the entire website using one button (Disable Caching) in the administrative part on the page Cache Settings Settings > System settings > Cache Settings.

As a rule, it is deactivated at the development stage and is activated before the delivery of the project. Do not expect Bitrix Framework itself to choose the caching time and the right moment to do so for a cache flush. Only the developer can do that based on the actual needs of each project: the caching time that is suitable for the information update frequency must be indicated in the component settings.

Structure and Storage Place

Cache of the components is stored in the files of the folder /bitrix/cache.

Component cache identifier is generated based on the following parameters:
  • ID of the current website which determines the path to the cache file (alternative storage means may be used, but it does not affect the work with components),
  • Component name,
  • Component template name,
  • Component parameters,
  • External conditions determined in the component (e.g., list of groups to which the current user is connected).

In knowing all of these parameters, it is possible to flush the cache of any component. Otherwise, the cache will be reset upon the expiry of the cache time, by the click of a button on the control panel of the public part, or by performing complete cache flush from the administrative part.

Note: When you reset the cache of a page using the “Refresh Cache” button, please keep in mind that the component may use the binding to groups for cache storage; in this case, non-registered users will continue seeing an outdated page.

The cache of public components is not reset immediately after adding/changing an infoblock element in the administrative part. This is because, for example, the News information block "does not know", where the news is displayed in the public part and how many components display it. It causes no problems if the caching time is set correctly.

Component Workflow Structure

$arParams contains a set of component parameters, component.php works with request input parameters and database, generates a result to the array$arResult. Component template converts results into HTML text.

Upon the first hit, the generated HTML goes to cache. With subsequent hits, no (or very few) queries are made to the database since the data are read from the cache.

Attention! Please keep in mind the order of execution; in this case, the component template code and result_modifier.php are not executed.

Frequent error: in the component template, deferred functions are retrieved: $APPLICATION->SetTitle(), $APPLICATION->AddChainItem() etc. In this case, they work only if caching is off.

When developing the templates of own components, the developer shall follow a simple rule: the template’s task is to generate HTML text on return based on the input array $arResult.

The generated cache ID of own components must be capable of unambiguously determining the resulting html. However, avoid sending too much data to the cache ID. That results in wasting disc space and reduces cache hits (thereby making cache less efficient).



Courses developed by Bitrix24