Flex uses an in-memory cache to handle requests for MXML pages. The first time it invokes an MXML page, the compiler creates an SWF file and stores it in the Flex cache. Flex also creates and caches an HTML wrapper page, and serves subsequent page requests from this cache. Figure 1 shows the flow of traffic.
Figure 1. Caching requests for MXML pages
Flex also caches dependent files such as SWC, MXML, and ActionScript files. Flex keeps a reference of all dependent files, such as CSS style sheets, images used in the <mx:Image> tag, and ActionScript files included with the <mx:Script> tag, and stores them in the /WEB-INF/flex/cache.dep file. If any of these dependent files change, Flex recompiles the MXML file.
The Flex caching settings are configured in the <cache>...</cache> section of the flex-config.xml configuration file. Flex enables caching by default, using the entry <cache-mxml>true</cache-mxml>. If you set this entry to false, all requests to an MXML file force a recompilation of the MXML document. The <content-size>500</content-size> entry in the flex-config.xml file defines the default maximum size of the cache, 500 entries. The content-value size is not defined by the total number of MXML files, but by the total number of cached entries. For example, a single MXML file writes two entries in the cache: one for the HTML shell and one for the SWF file. In most cases, the default setting of 500 is more than enough but there might be cases in large enterprise applications where you have a sizeable number of MXML documents. Flex will create additional cache entries for different URL pairs (for example, page.mxml?accessible=true). By setting accessible=true in the URL, you create a new unique SWF file and HTML shell that is added to the cache. There is not a significant amount of memory overhead to increasing this value because most HTML shells are only a few kilobytes in size and most Flex SWF files are around 100 to 150K.
When you use the JSP tag library to inline MXML into a JSP or CFML page, Flex uses a separate cache for the MXML code fragments. Flex defines this cache with the <mxml-size> entry with a default value of 500. The following example shows a code fragment from a JSP page:
<mx:Application> <mx:Label text="Hello"/> </mx:Application>
Flex caches this code fragment in the source cache defined by the <mxml-size> entry. The resulting SWF file and HTML shell generated from compiling the source are cached in the content cache, defined in the <content-size> caching setting. If at anytime the source fragment changes within the page, a new cache entry is entered into the source cache, and Flex compiles a new SWF file.
<mm:mxml> <mx:Application> <mx:Label text="Hello" /> </mx:Application> </mm:mxml>
When Flex reaches the size limit in a cache, it flushes the least recently used file. In Flex 1.0 there is no way to see how many entries are in the cache and there is no way to flush the cache while the server is running. As you will see in the next section, this is only a problem if the server is running with production-mode=true. During development, the file-watcher monitors all dependent files defined in /WEB-INF/flex/cache.dep; if a file changes, Flex recompiles the corresponding MXML file and refreshes the cache. For more details on the caching implementation in Flex, read the Configuring Caching section in the Developing Flex Applications documentation.