Home
Idgenerator and metadatagenerator sub-elements
Use the Idgenerator element to specify the class name that is loaded for the generation of the cache ID. The Idgenerator element must implement the com.ibm.websphere.servlet.cache.Idgenerator interface for a servlet or the com.ibm.websphere.webservices.Idgenerator interface for the Web services client cache. An example of the Idgenerator element follows:
<Idgenerator> class name </Idgenerator>Class name is the fully qualified name of the class to use. Define this generator class in a shared library. Example | -30 shows an example of a custom written command cache ID generator.
Example 6-30 Cache ID generator for a command object
package com.ibm.ws.cache.command;import com.ibm.websphere.command.*;import java.util.*;public class QuoteIdgenerator implements CommandIdgenerator {public String getId(CacheableCommand command, ArrayList groupIds) {QuoteCommand cs = (QuoteCommand)command;// add dependency ids for quotecommand the ticker for this commandgroupIds.add("QuoteCommandIDGen");groupIds.add("ticker:"+cs.getTicker());return "QuoteCommmandIdGen Ticker:"+cs.getTicker();}}
Use the metadatagenerator element inside the cache-id element to specify the class name loaded for the metadata generation. The MetaDataGenerator class must implement the com.ibm.websphere.servlet.cache.MetaDataGenerator interface for a servlet or the com.ibm.websphere.cache.webservices.MetaDataGenerator interface for Web services client cache. The MetaDataGenerator class defines properties like timeout, inactivity, external caching properties or dependencies. An example of the metadatagenerator element is:
<metadatagenerator> class name </metadatagenerator>In this example, class name is the fully qualified name of the class to use. Define this generator class in a shared library.
Example 6-31 Sample metadata generator source code
package com.ibm.ws.cache.servlet;import javax.servlet.http.*;import com.ibm.websphere.servlet.cache.*;public class MyMetaDataGenerator implements MetaDataGenerator {private int timeout=0;private int priority=0;public void setMetaData(ServletCacheRequest req, HttpServletResponse resp) {System.out.println("**** setMetaData***");FragmentInfo fragmentInfo = (FragmentInfo) req.getFragmentInfo();String tout = req.getParameter("metaDataTimeout");if (tout != null) {timeout = new Integer(tout).intValue();if (timeout != 0) {fragmentInfo.setTimeLimit(timeout);}}String pri = req.getParameter("metaDataPriority");if (pri != null) {priority = new Integer(pri).intValue();if (priority!=0) {fragmentInfo.setPriority(priority);}}}public void initialize(CacheConfig cc) {}}