ATG Repository Caching Do's

Caching: ATG prints lot of SQL queries on console if you turn on SQL debug info. Most of the developers get confused how this can optimize database operation. The following paragraph will answer all such doubts:

The item caches hold the values of repository items. Repository queries are performed in two passes, using two separate SELECT statements. The first statement gathers the IDs of the repository items that match that query. The SQL repository then examines the result set from the first SELECT statement and finds any items that already exist in the item cache. A second SELECT statement retrieves from the database any items that are not in the item cache.

If query caching is enabled, the first time a query is issued, the result set is retrieved from the database and stored in the query cache. Then, the next time this same query is issued, the SQL repository can retrieve the result set from the cache, rather than needing to access the database. This cache only hold repository ids not all items and it fetch all the available items from Item cache and goes to db for rest of the items. i.e. your query return 200 items then query cache will hold 200 ids (which are just string objects) and if ATG found 190 items in item cache the repository will fetch 190 from cache and will retrieve remaining 10 items from db.

Use cacheReferencesById attribute of property, in some cases, you might have a property in a repository item that references a large sub-tree of items. Then, you can use the tag to set the attribute cacheReferencesById=true. The SQL Repository then will not store the repository items referred to, but will instead store only the repository IDs of the items referred to in the item cache.


Post a Comment

Related Posts Plugin for WordPress, Blogger...