When implementing cache support in custom components, the following rules should be observed by a developer.
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:
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.