When implementing cache support in custom components, the following rules should be observed by a developer.

1. In cached mode, a component must not perform database API calls or request data from database in any other way. Unfortunately, a developer may unwillingly make coding mistakes which allow database API calls to bleed through even in cached mode.
2. When a component cannot find cached data for requested parameters, it has to create such data and put it to the cache. When creating new data, the component's database API calls must be painstakingly optimized. Sometimes coding errors may cause excessive database load performing enormous amount of SQL queries.

It is recommended that you carefully analyze all database queries a component performs and optimize the code by using filters, proper sort modes and reducing the number of properties to fetch.

To analyze the SQL queries, the EXPLAIN command will come in handy for you. Make sure your SQL selections use database indexes. This can be of great importance for Components 2.0 because they can create indexes for columns of the information block element properties table.

This approach should also be applied to database API calls in the service and initialization scripts. Even if an optimized component is robust, fast and uses caching, it may interact with an initialization script that executes an outburst of numerous SQL queries which will kill all your optimization efforts.

To streamline your database optimization work, create and use an optimization status table:

- Column 1: Web page address.
- Column 2: SQL query count, cache disabled.
- Column 3: SQL query count, cache enabled.
- Column 4: SQL queries optimized. (using the approach described above)

Check all the website pages and fill the table with performance data. Your aim is to get the numbers in (3) as small as possible (zero SQL queries is the ideal value; the Web Analytics module, if used, may produce some surplus which is normal); the number of SQL queries in (2) must be reduced to a bare minimum. Once you have optimized a page, make a note in column (4).

You can use this table for your custom components if you like.

1. Create and populate an optimization status table. If time presses, measure performance of the most visited pages only. Minimize database load by optimizing and adding cache functionality to unacceptably aggressive components.
2. Ensure that all the service and initialization scripts are also optimized and that they use only the Bitrix Framework API calls to execute database queries. Direct database queries are not allowed.