Set cache expiration time according to server response field value

Hello there!

I have few endpoints and by default response cache expiration time set to 10 minutes.

Also, I have /employee endpoint and I want in this particular case change cache expiration time to 2 minutes if in a server response "vacation" field holds true value.

Could I achieve it using only policies or I have to use scripts with node.js? How can I rewrite the default expiration time?

0 3 300
3 REPLIES 3

Hi @Sergey Rastrigin, is the default response cache implemented in Apigee?

yes, it's just response cache policy

You should be able to use the ExpirySettings/TimeoutInSecs element when configuring ResponseCache. You can reference a variable holding the required expiration time and a default value if that variable is not present

<ExpirySettings>
  <TimeoutInSec ref="duration_variable">600</TimeoutInSec>
</ExpirySettings>

https://docs.apigee.com/api-platform/reference/policies/response-cache-policy#ExpirySettingsElement