Caching stores responses for requests that are identical and therefore enhances the response times for subsequent requests. When caching is enabled, subsequent requests with the same hash value as the previous request whose response was cached, will be served with the same cached response.
Caching can be enabled at three levels as follows:
- Global-Level : Caches responses from all the services in a hosted server instance. For information, see Configuring the wso2caching Module.
- Service-Level Response CachingOperation-Level : Caches only responses from a particular operation of a given service. For information, see Operation Management.
- Service-Level : Caches only the responses generated by the operations of a particular service as described below.
Note |
---|
It is advisable to consider the dynamic nature of your services before enabling caching globally. For example, an operation that generates random numbers might not benefit by caching previous responses, because it generates a unique response for each invocation anyway. |
Service-level response caching
Follow the steps below to add response caching to a service.
- Log in to the management console and select Services > List under the Main menu.
- From the Deployed Services page that appears, click the service to which you want to enable caching.
- The service's dashboard opens. Click Response Caching from the Quality of Service Configuration panel.
- Enable caching to the service by selecting Yes.
- The last saved configuration or Change the default configuration (if it is the first time) for caching will be displayed.
Fields in Wizard
- caching configuration settings as you need.
The options of the above window are as follows:
- Hash Generator
- : Specifies the fully qualified class name of the hash value generator. This class implements the
org.wso2.caching.digest.DigestGenerator
interface. It is responsible for generating a
- : Specifies the fully qualified class name of the hash value generator. This class implements the
- Hash
- value for each request message, so that a matching response message can be located from the cache. The default is
org.wso2.caching.digest.DOMHASHGenerator
. You can implement your own
- value for each request message, so that a matching response message can be located from the cache. The default is
- Hash
- generator class and use it with the WSO2
- products. However, the default hash generator
- is enough for general use.
- Timeout
- : Shows the time period, in milliseconds,
- during which a cached response is kept in memory. The counting starts from the time the first request is received. Any request
- received after the counter has started and is within the Timeout period
- is served with the response cached upon receiving the first request. Once the Timeout expires, the cache will be updated with the response generated for the first request that was received after the expiry.
- Maximum Cache Size
- : Holds the maximum number of response messages that
- are cached. If the maximum number of responses are already cached and none of the cached responses' Timeouts have expired, then future responses are not cached until this memory is free enough to accommodate
- a new response.
- Maximum Message Size
- : Shows the response message that is cached. Response messages larger than this (in size) are not cached. Caching is an expensive operation for larger messages, especially given the amount of memory required. Therefore, this value should be set considering the performance and resource trade-offs.
Info | ||
---|---|---|
| ||
It is advised that you consider the dynamic nature of your services before enabling caching globally. For example, an operation that is supposed to generate random numbers would not benefit from caching previous responses, because it is supposed to generate a unique response for each invocation. |
6. Click "Finish." Caching will be engaged for that particular service.
Functions of Buttons:
- Finish - Click "Finish" to submit the current data. When finished, your throttle configuration will be applied and the page will be redirected to the previous page.
- Reset - Click "Reset" to load the last submitted configuration.
- Default - Click "Default" to load the default throttle configuration. If you want to submit those data, you have to click "Finish."
- Clear - Click "Clear" to clear all the text boxes in the user interface.
- Cancel - Click "Cancel" to go to the "Service Dashboard" page.
hidden | true |
---|
- Click Finish after the config is done.
The rest of the function of buttons on this window are as follows:
- Finish : Submits the current data
- Reset : Loads the last submitted configuration
- Default : Loads the default RM configuration. (Click Finish to submit)
- Clear : Clears he text boxes
- Cancel : Goes back to the service dashboard