Cache Job Results

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Job Configuration Examples >

Cache Job Results

This example shows you how to cache the result of a job (referred to as cache producer) and use it in another job (referred to as cache consumer). Both jobs will be exposed as Web services with the following behavior:

 

When the cache producer Web service is invoked, it lists recursively the contents of the directory, creates or updates the cache, and then outputs the result in the browser;
When the cache consumer Web service is invoked, it reads the cache created by the cache producer service and outputs the result in the browser.

 

Our goal is to compare the execution time of both jobs, and see that the second job executes significantly faster than the first job, since it consumes cached data.

 

Prerequisites

Required licenses: FlowForce Server
FlowForce Server is running at the configured network address and port (see Setting the Network Address and Port)
You have a FlowForce Server user account with permissions to one of the containers (by default, the /public container is accessible to any authenticated user).

 

Tip

Although this example uses Windows paths and commands, you can still test it on other operating systems, if you change the paths and the commands accordingly.

 

Creating the cache producer and the cache consumer jobs

1.Click Configuration, and then navigate to the /public container.
2.Click Create, and then select Create Job.
3.In the Job Name box, enter DirectoryListing.
4.Under Execution Steps, add a new execution step with the following settings:

 

Execute function

Browse for the /system/shell/commandline function.

Command

Enter the following shell command:

 

dir /s

 

On Windows, this command lists recursively the contents of the working directory (see the next setting).

Working directory

Set the value to a directory on the machine where FlowForce Server runs, for example:

 

c:\

Assign this step's result to

We will need to refer to the value returned by the execution step in a subsequent step, so it must have a name. For the scope of this example, enter dir as value of this field.

 

5.Under Execution Steps, add a new execution step with the following settings:

 

Execute function

Browse for the /system/compute function.

Expression

Enter the following FlowForce Server expression:

 

stdout(dir)

 

The stdout function converts the raw result returned by the previous execution step into a stream of data (see Step Result Functions).

 

6.Under Execution Result, set the return type to stream. As you might have noticed, we set it to the same data type as returned by the last execution step of the job.
7.Under Caching Result, select the Cache the result check box.
8.Select the Auto-create a new cache consumer job check box, and then enter DirectoryListingCached as the name of the Web service.
9.Under Service, click to select the Make this job available via HTTP check box, and enter DirectoryListing as name of the service.

 

At this stage, the job should look as follows (provided you did not use different paths or shell commands).

ExampleCacheJob

10.Under Credentials, select an existing credential record or specify a local credential (see Credentials).
11.Click Save.

 

 

At this stage, you have completed the configuration of both the cache producer and the cache consumer jobs. To compare the performance of both jobs, you can do the following:

 

1.Access the URL of the cache producer service (DirectoryListing) in the browser, that is http://[FlowForceServer]:[Port]/service/DirectoryListing (if you are having trouble accessing the Web service, check the configured network address and port). Note that, because the job was configured to list the contents of the c:\ directory recursively, it might take up to several minutes to complete.
2.Refer to the job log to see how long it took for the job to complete (see Viewing the Job Log).
3.Next, do the same for the cache consumer service (DirectoryListingCached). Since this service consumes the cache rather than executing the directory listing, it is expected to take significantly less time to complete.

© 2019 Altova GmbH