0

I need to implement business logic when the entire response is cached in APIM internally based on one path parameter. E.g. the URI is:

https://<apimhostname>/mycustomapi/v1/domains/<domain_id>/services

Based on domain_id path parameter, during the GET operation, I need to cache the entire response for specific domain_id and then return it back to the client during subsequent requests with given domain id. The number of possible domain_id values is less than 10.

I see vary-by-query-parameter policy which caches the entire response per value of specified query parameters. But, in fact, I do not have query parameters. On the other side, there is cache-store-value policy which allows storing the value by key. In my case the key is domain_id but I am not sure whether it is possible to store the entire response in that way.

Which approach is better to use in that case to cache the entire response based on path parameter?

Also, I have an Authorization header with an access token that is validated (iss and aud) on APIM side (validate-jwt policy), however, my backend validates the 'roles' claim. So when I reply back with a response from cache are there any ways to validate the role claim on APIM side?

Thanks.

easkerov
  • 15
  • 1
  • 6
  • cache-store/cache-lookup policies by default store response for URI invoked + any extra vary-by-* specified. Any reason why you can't just use the policy? – Vitaliy Kurokhtin Mar 16 '22 at 20:32
  • @VitaliyKurokhtin could you please be more specific? Or provide some example please. – easkerov Mar 17 '22 at 11:21

1 Answers1

1

Cache store policy (https://learn.microsoft.com/en-us/azure/api-management/api-management-caching-policies#StoreToCache) will do what you need to do:

<policies>
    <inbound>
        <base />
        <cache-lookup vary-by-developer="true" vary-by-developer-groups="false"/>
    </inbound>
    <outbound>
        <base />
        <cache-store duration="3600" />
    </outbound>
</policies>

The policy above takes request URL into account event if it's processed by the same APIM operation. I.e. request to https://<apimhostname>/mycustomapi/v1/domains/1/services and https://<apimhostname>/mycustomapi/v1/domains/2/services will be cached separately.

Vitaliy Kurokhtin
  • 7,205
  • 1
  • 19
  • 18