Sei sulla pagina 1di 3

Extending the ATG Platform

Chapter 8: Repository Caching


Catching Up
Completion of Chapter 7 is not required in order to complete the remaining exercises. However, if you were unable to finish and would like to catch up Complete the Catching Up section from the previous chapter. Copy solutions\chapter07\songs.xml to the DynamusicEAP\config\dynamusic folder. Copy the JSP file in solutions\chapter07\ to the DynamusicEAP\j2ee-apps\dynamusic-j2ee\dynamusic.war folder.

Exercise 1: Pre-loading SQL Repository Cache


Exercise Objective
After completing this exercise, you will be able to configure SQL Repository caching and review caching statistics.

Problem Statement
Pre-load all the items in the Songs Repository when the repository starts up Enable query caching on items in the Songs Repository Review caching statistics

Guided Instruction
Pre-load the Songs Repository cache Pre-loading the cache involves querying the repository defined in a repository definition file using XML repository operation tags. 1. Before setting up cache pre-loading , view the cache statistics. Open the ATG Administration interface at http://localhost:8080/dyn/admin and select the Component Browser. Browse to the /dynamusic/SongsRepository component and note the Cache usage statistics section of the page.

Chapter 8: Exercises

8-1

Extending the ATG Platform 2. Click Reset Cache Statistics so you will see fresh statistics the next time you restart ATG.

3. Edit the songs.xml file directly in Eclipse or another text editor. At the end of the file, after all the item-descriptor tags but before the closing gsatemplate tag, add a query-items tag for each of the three item types in the Songs Repository song, album and artist. The query-items tags will generate a potentially huge amount of output on start-up; to avoid this you can add the quiet="true" attribute to the tags. For this exercise, try adding quiet="true" to the song and album queries, but not to the artist query so that you can become familiar with the debug output. 4. Test your repository modifications using startSQLRepository. Note the query output. Resolve any errors before continuing. 5. Restart ATG. 6. Return to the SongsRepository page in the Component Browser, and examine the Cache usage statistics. 7. In a separate browser window, clear the cached pages in your browser (e.g., the temporary internet files in IE), then browse through several artists, albums and songs on the Dynamusic site. Reload the cache statistic page and note the cache hits. Configure query caching By default, query caching is disabled, as indicated on the Cache usage statistics page. You can enable it by setting the query cache size to a number greater than 0, which is the default value. 8. In each item-descriptor tag in songs.xml, add query-cachesize="100". 9. Test your repository modifications using startSQLRepository.

8-2

Chapter 8: Exercises

Extending the ATG Platform 10. Restart ATG. 11. Browse through several albums, artists and songs on the site, and then reload the Cache usage statistics page. Note that query caches are no longer disabled; instead they appear and show several reused queries. Note: Queries occur on several pages in the site. Look at song.jsp for an example. Manually invalidate the cache 12. Go to the SongsRepository page in the Component Browser. Find the Methods section, and locate the invalidateCaches method. Click on the method name to invoke it.

13. Reload the SongsRepository page and note that the caches are now empty.

Chapter 8: Exercises

8-3

Potrebbero piacerti anche