Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 17 Advanced Features : Response Caching

Response Caching
TIBCO API Exchange Gateway can cache response messages from the target services. The response caching functionality is supported for HTTP(s)/REST and HTTP(s)/SOAP requests. To enable caching of response messages from the target services for any facade operation, see Enable Response Caching.
Response caching is supported by the CacheEnabled operation feature of TIBCO API Exchange Gateway. If the CacheEnabled keyword is specified in the Operation Feature and the caching is not explicitly configured on the Config UI for a facade operation, TIBCO API Exchange Gateway uses the default caching parameters as follows:
Cache Type: Simple Cache
Time To Live: 1 day (24 hours)
Types of Response Caching
The following types of response caching are supported:
Facade Response Cache (Simple Cache)
The Facade Response Cache is known as Simple Cache. If the Simple Cache type is enabled as response caching for a facade operation, the Core Engine processes the incoming facade requests as follows:
When the response message is received from the target service by the Core Engine for the first time, the Core Engine stores the response message including the headers in the cache using the cache response key. See Cache Response Key. For every subsequent requests from the client, the response from the cache is returned with all the response headers, similar to the response headers from the target service. The X-Cache: Hit in the response message header indicates that the response message is returned from the cache.
Sample Request Header
The following is the sample request header for the facade request with accept header:

 
<h:request xmlns:h="http://www.tibco.com/asg/protocols/http">
<h:server-ip>localhost</h:server-ip>
<h:server-port>9222</h:server-port>
<h:client-ip>0:0:0:0:0:0:0:1</h:client-ip>
<h:client-port>0</h:client-port>
<h:scheme>http</h:scheme>
<h:method>GET</h:method>
<h:request-uri>/Books/BookOperations/Title/The Power of Now</h:request-uri>
<h:protocol-version>HTTP/1.1</h:protocol-version>
<h:query-string/>
<h:header name="host">localhost:9222</h:header>
<h:header name="connection">keep-alive</h:header>
<h:header name="accept">
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
</h:header>

 
 
Sample Response Headers
The following are sample response headers for the facade response caching type:
Sample Response Headers from Target Service

 
Access-Control-Allow-Origin: *
Date: Wed, 13 Aug 2014 20:59:06 GMT
Server: Apache-Coyote/1.1
Connection: Keep-Alive
Transfer-Encoding: chunked
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Content-Type: application/json;charset=ISO-8859-1

 
Sample Response Headers from Cached Response

 
Access-Control-Allow-Origin: *
Date: Wed, 13 Aug 2014 20:59:06 GMT
X-Cache: Hit
Server: Apache-Coyote/1.1
Connection: Keep-Alive
Transfer-Encoding: chunked
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Content-Type: application/json;charset=ISO-8859-1

 
Target Backup Response Cache
The Target Backup Response Cache is known as Backup Cache. The Target Backup Response Cache ensures that the response message is sent from the cache (if existing) to the client in case the response is not received from the target service within a time period.
If the response caching of Improve SLA type is enabled for a facade operation, the Core Engine processes the incoming facade request as follows:
For any request from the client, if the response from the target service is not received within a configured time period specified by the Short Wait Timer parameter, the Core Engine fetches the response message stored in the cache.
a.
b.
c.
Cache Response Key
TIBCO API Exchange Gateway uses the cache response key to check if a cached response exists in the cache for an incoming request.
By default, the Core Engine constructs the value of the cache response key for REST/HTTP requests using the following parameters:
routingKey+requestURI(minus the API Key)+Accept-Header+Soap Action
where,
Accept-Header: The Accept HTTP request-header may be used to pass a content-type preference to the target service. For example, a service may support an Accept-Header of application/xml or application/json to preferentially return the response message in XML or JSON format. For the purpose of caching, the request with Accept-Header of application/xml or application/json are managed as two separate requests. The Accept-Header is added to the cache response key as an additional discriminator.
For example, if a user requests the JSON data for a URI such as /Books/BookOperations/Title/Power , the cached response is only returned if the cache value has a JSON response for that URI in the cache.
For HTTP/REST and HTTP/SOAP requests, the Core Engine creates a default caching key using the above parameters..
Response Caching with Proxy Server
For the Proxy operation feature of TIBCO API Exchange Gateway, the response caching is supported as follows:
If the caching is explicitly configured for a facade operation on the Config UI, TIBCO API Exchange Gateway uses the Cache Type and other caching parameters such as Time To Live as configured for the facade operation.
Cache Type: Simple Cache
Time To Live: 1 day (24 hours)
Enable Response Caching
To enable the response caching for a facade operation request, follow these steps::
1.
2.
3.
4.
Click the ROUTING tab on the right-hand side.
5.
Click the Facade Operations tab.
6.
7.
Select the Enable Caching check box.
8.
Response Caching Parameters
The following table explains the parameters required for response caching:
This parameter is not applicable for Simple Cache response caching type.
Clear Cached Items
The cached messages are deleted after the time specified by Time To Live parameter. Start the Cache Cleanup Agent to clear the cached response messages as follows:
1.
Navigate to the ASG_HOME/bin directory.
2.
On Windows platform,
./asg-engine.exe -u asg-cache-cleanup
On Unix platform,
asg-engine -u asg-cache-cleanup
Override Cache Response Key and Parameters
Using TIBCO API Exchange Gateway, you can override the following parameters for a specific facade operation request:
See Cache Response Key.
The Cache Response Key and Cache Response parameters can be overwritten using a custom XSLT file.
To overide the cache response key and cache response parameters, follow these tasks:
 
Task A Create XSLT File
Create an XSLT file with the following key types to specify the new values for the cache response. Refer to Sample XSLT File.
Task B Upload XSLT File
To upload the XSLT file, follow these steps:
1.
2.
3.
4.
Click the ROUTING tab on the right-hand side.
5.
Click the Facade Operations tab.
6.
7.
Upload the XSLT file in the New ProcessBody Transform field.
8.
If you copy the XSLT file to the ASG_CONFIG_HOME/ASGProjectConfig/xslt directory, select the XSLT file in the ProcessBody Transform field of the Facade Operations tab.
Sample XSLT File
The following is an example XSLT file which can be used to override the cache response key and response caching parameters:

 
<!-- The key used to check if a cached response exists for this request -->
<key type="CacheResponse_Key"><xsl:value-of select="$httpRequest/h:request/h:request-uri"/></key>
 
<!-- This is how long (in milliseconds) we wait for the response from the service before sending a cached response instead -->
<key type="CacheResponse_ShortWait">4000</key>
 
<!-- This is the time (in seconds) that the response will be retained in the cache -->
<key type="CacheResponse_TTL">50</key>
 
<!-- What caching semantics are applied?
simpleCache - return a value from cache if present, otherwise invoke service and put response in cache.
improveSLA - use a cached value if the service takes more than ShortWait ms to reply. Freshen value in cache with real response.
-->
<key type="xCacheResponse_Type">simpleCache</key>

 
Response Caching Example
Out of the box, TIBCO API Exchange Gateway provides a BookQueryBE example. By default ,the queryBookByTitle facade operation is enabled for simple cache response type.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved