Network Deployment (Distributed operating systems), v8.0 > Reference > Developer examples

Example: Caching a command object

Cacheable commands are stored in the cache for reuse with a similar mechanism for servlets and JSP files.

This example of command caching is a simple stock quote command.


The following is a stock quote command bean. It accepts a ticker as an input parameter and produces a price as its output parameter.
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;};


To cache the above command object using the stock ticker as the cache key and using a 60 second time-to-live, use the following cache policy:
<component type="method" id="getTicker">

Configure command caching


Search Tips   |   Advanced Search