For stateless components, you can configure method results caching. In this configuration, EAServer caches method return codes using a key composed of the input parameter values. When handling an incoming request, EAServer checks for a valid cached entry. If the cache contains a valid result, EAServer returns the cached return code rather than invoking the business method. To use this feature, your component must satisfy these requirements:
The component must be an EJB stateless session bean, or a CORBA component wrapped by one. For CORBA and PowerBuilder components, the Stateful Session Bean component property must be disabled.
The business method must return values (have a return type other than void) and have the same semantics whether it is called once for a given set of input values or multiple times. For example, you cannot enable results caching for a method that increments counters or creates new database rows every time it is called, regardless of input. Doing so would change the behavior of the application. On the other hand, if multiple calls with the same set of input values result in the same database end state, you can use method results caching.
The business method must perform database lookups or other time-consuming processing. Methods that do simple calculations are unlikely to be worth caching, since the overhead of caching is likely equal to or greater than calling the method in the first place.
The business method must operate on small input values. EAServer stores input values in memory as part of the cache key. Large input values will consume too much memory when the method results are cached.
If the method results depend on data that can change independently of method execution, your application must include some mechanism to prevent the use of stale cache data. Use one of the following options:
Configure and use a database version table. The version table contains a single row containing a an integer column that changes when data that affects the method outcome has changed. For example, if the method queries a database, you can configure database triggers on the tables that affect the method result to update the version table row.
Configure a finite cache timeout. Cached values older than the timeout are discarded. This option can result in a larger performance gain since it removes the overhead of querying the database version table. However, it should not be used if stale data is never acceptable.
To configure method caching, run the <cacheResult> property task in the Ant user-configuration file for the EJB module that contains the stateless session bean to be configured. To configure a CORBA or PowerBuilder component, perform this configuration on the EJB module that contains the EJB wrapper components for the CORBA package. Here is an example configure-user target that configures a version table:
<target name="configure-user"> <setProperties component="ejb.components.myjar.MyCompRemote"> <cacheResult method="getProductInfo(java.lang.Integer)" cacheSize="100" dataSource="myDataSource" tableVersion="ref_tv.version" /> </setProperties> </target>
Here is another example that configures a cache timeout:
<target name="configure-user"> <setProperties component="ejb.components.myjar.MyCompRemote"> <cacheResult method="getProductInfo(java.lang.Integer)" cacheSize="100" cacheTimeout="60" /> </setProperties> </target>
The table below describes the attribute values used in the examples:
Attribute |
Description |
---|---|
|
Specifies the name of the DJC component that runs the application component that you want to monitor. Set this depending on the application component type, as follows:
|
|
Specifies the Java name and signature of the business method. If omitted, the cache configuration applies to all non-void methods in the component. |
|
The maximum number of results that will be held in cache. To avoid overflow, rows are removed from cache using a least-recently-used (LRU) discard strategy. If not specified, the default is 1000. |
|
The maximum number of seconds that a result stored in cache will be considered valid. This property should not be used to attempt to control the cache size, because invalid results are only discarded from cache when an attempt is made to access them. A value of zero is interpreted as an infinite timeout. The default is zero. |
|
If a version table is required, specifies the name of the data source to connect to the database in which the table is located. |
|
If a version table is required, specifies
the table name and the name of the column that contains the version
number. For example, |