WebSphere Application Server, Version 6.0.x   
             オペレーティング・システム: AIX , HP-UX, Linux, Solaris, Windows

             目次と検索結果のパーソナライズ化

例: コマンド・オブジェクトのキャッシュ

キャッシュ可能なコマンドは、サーブレットおよび JavaServer Pages (JSP) ファイルの同様のメカニズムで再使用するために、キャッシュに保管されます。

このコマンド・キャッシング例は、 簡単な株価情報コマンドです。

次に示すのは、株価情報コマンド Bean です。 これは、入力パラメーターとして ticker を受け取り、 出力パラメーターとして price を生成します。
public class QuoteCommand extends CacheableCommandImpl
{
    private String ticker;
    private double price;
    // called to validate that command input parameters have been set
    public boolean isReadyToCallExecute() {
      return (ticker!=null);
    }
    // called by a cache-hit to copy output properties to this object
    public void setOutputProperties(TargetableCommand fromCommand) {
        QuoteCommand f = (QuoteCommand)fromCommand;
        this.price = f.price;
    }

   // business logic method called when the stock price must be retrieved
    public void performExecute()throws Exception {...}

    //input parameters for the command
    public void setTicker(String ticker) { this.ticker=ticker;}
    public String getTicker() { return ticker;}

    //output parameters for the command
    public double getPrice()  { return price;};
}

キャッシュ・キーとして stock ticker を使用し、60 秒の存続時間を使用して、 上記のコマンド・オブジェクトをキャッシュに入れる場合は、 以下のキャッシュ・ポリシーを使用します。
<cache>
	<cache-entry>
		<class>command</class>
		<sharing-policy>not-shared</sharing-policy>
		<name>QuoteCommand</name>
		<cache-id>
				<component type="method" id="getTicker">
				<required>true</required>
			</component>
				<priority>3</priority>
				<timeout>60</timeout>
		</cache-id>
	</cache-entry>
</cache>



関連タスク
コマンド・キャッシングの構成
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 22, 2008 12:07:38 AM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/rdyn_commandxmp.html