You can configure API cache information to cache the API response and relieve the stress on the business system.
API cache covers the response of all backend requests, including response header and response body. So, the response headers of the cached APIs must have the status information eliminated, such as user-mode data in
cookie. This cache function is only applicable for caching stateless data.
The backend business system can inform the gateway of not caching response by adding
Pragma: no-cache in the response header.
- Log in to the mPaaS console, and from the navigation bar on the left, click Mobile Gateway Service.
- In the API list, select the API to be configured, and click Configure on the operation column to go to the API detail page.
- Click Edit in the Cache configuration section, and then configure the following rule:
- Cache result: Whether to cache or not
- Cache time: Cache’s time to live, in seconds
- Cache key: Key expression used for caching. Click Modify to define the cache key. In the pop-up modal dialog box, enter the required primary key. You can drag the keys to sort them. For information about the key syntax, see Key syntax.
When the gateway receives an API request, it obtains the corresponding data from the request according to the key configuration and uses the data as the cached key.
The syntax is as follows:
|$||Root object, for example:
|[num]||Array access, num refers to number, for example:
|.||Attribute access, for example:
|[‘key’]||Attribute access, for example:
|$.header||API request header object, used to obtain the field in the request header, for example:
|$.cookie||API request cookie object, used to obtain the value in cookie, for example:
|$.http_body||HTTP request body object, used to obtain the field in the request body, for example:
|$.http_qs||HTTP request parameter object, used to obtain the request parameter, for example:
For example, to obtain objects from the following request message:
Here are examples of the expression:
$.header.appId = B2D553102
$.cookie.traceId = trace1000
$.http_qs.tenantId = boo
$.key = 1234
$.locations = shagnhai
$.demo.name = nick