Why does Apigee 4G cache http response code 503?

Not applicable
 
Solved Solved
0 3 688
1 ACCEPTED SOLUTION

Not applicable

By default, Apigee Edge only caches 2xx level responses. Non-2xx responses are not cached, see http://apigee.com/docs/api-services/content/http-response-caching.

Please check your HTTPTargetConnection definition and see if it is treating 5XX as success codes. For example:

<HTTPTargetConnection>

<Properties>

<Property name="success.codes">1XX, 2XX, 3XX, 4XX, 5XX</Property>

</Properties>

You could remove 5XX from the "success.codes" property above so that the 503 status code is no longer cached.

If you need to keep the 5XX response codes as success codes and do not want to cache the 503 response code, then there are a couple of options.

The first option would be to use the SkipCachePopulation element in the ResponseCache policy. Please see http://stackoverflow.com/questions/22451617/cache-policy-caching-only-if-request-succeeded or http://apigee.com/docs/api-services/content/best-practices-api-proxy-design-and-development

The second option would be to, in the response flow, add a condition check in the step that populates the cache to only populate the ResponsCache policy if the response.status.code is not 503.

<Response>

<Step>

<Condition>(response.status.code!= 503)</Condition>

<Name>ResponseCache</Name>

</Step>

</Response>

View solution in original post

3 REPLIES 3

Not applicable

By default, Apigee Edge only caches 2xx level responses. Non-2xx responses are not cached, see http://apigee.com/docs/api-services/content/http-response-caching.

Please check your HTTPTargetConnection definition and see if it is treating 5XX as success codes. For example:

<HTTPTargetConnection>

<Properties>

<Property name="success.codes">1XX, 2XX, 3XX, 4XX, 5XX</Property>

</Properties>

You could remove 5XX from the "success.codes" property above so that the 503 status code is no longer cached.

If you need to keep the 5XX response codes as success codes and do not want to cache the 503 response code, then there are a couple of options.

The first option would be to use the SkipCachePopulation element in the ResponseCache policy. Please see http://stackoverflow.com/questions/22451617/cache-policy-caching-only-if-request-succeeded or http://apigee.com/docs/api-services/content/best-practices-api-proxy-design-and-development

The second option would be to, in the response flow, add a condition check in the step that populates the cache to only populate the ResponsCache policy if the response.status.code is not 503.

<Response>

<Step>

<Condition>(response.status.code!= 503)</Condition>

<Name>ResponseCache</Name>

</Step>

</Response>

i have setup response cache policy for a resource as below for 10 minutes;

<?xml version="1.0" encoding="UTF-8"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="responseCache-getItemDetails">
   <DisplayName>responseCache-getItemDetails</DisplayName>
   <CacheKey>
      <KeyFragment ref="request.uri" />
   </CacheKey>
   <CacheResource>responseCache-getItemDetails</CacheResource>
   <ExcludeErrorResponse>true</ExcludeErrorResponse>
   <SkipCachePopulation>response.status.code != 200</SkipCachePopulation>
   <ExpirySettings>
      <TimeoutInSec>600</TimeoutInSec>
   </ExpirySettings>
</ResponseCache>

objective here is - not to expire cache when there's unhealthy response from backend, i.e. no 200 OK.

I am wondering if this a) SkipCachePopulation fulfills this objective, OR b) is there anyway in apigee can be done this ?

Not applicable

I have never seen such an error that occurs mainly with routers and Internet connections. When I first started looking for a good broadband connection it immediately struck me usave.co.uk which is very high-quality and effectively delivers a good Internet connection and all my games are loaded quickly enough. That is why I recommend this resource that will fit very well and beautifully into your life. I think you will also like this broadband Internet connection because it is quite efficient