Hi MS team and community,
I have set up a caching policy at the API Operation Level of a GET API with the example policies (see the bottom of this comment.
When I am testing, the caching is working as expected when I use the same subscription key. I then try to use different subscription keys, it is still working until I try the subscription keys of different API Product.
In my APIM, I have API Products of different API scopes and different policies. In the above case, there are 2 API Products, Product A and Product B, that both share the same API scope, both granting access to this API (refer as API A).
Since I have specified the 'vary-by-developer="false"'. If I made the first API call with the Product A subs key, I expect a cache hit when I made a second API request within the cache store duration with Product B subs key, but this result into a cache miss. This is verified in my Azure Diagnostic Logs.
I then look into the Trace for each of the API call in APIM's testing console. I noticed that the cacheKey is capturing the API Product ID.
e.g.
"cacheKey": "3_abc.azure-api.net.12_data.74482w-data;rev=12.194748_get-data.194749_8_https_abc.azurewebsites.net_443/api/data-api?dataType=Combined&pageNumber=1&Id=123123",
"cacheKey": "3_abcazure-api.net.12_data-premium.86443w-data;rev=12.194748_get-data.194749_8_https_abc.azurewebsites.net_443/api/data-api?dataType=Combined&pageNumber=1&Id=123123",
Can you please investigate if this is expected and how I can address this? I would like to achieve caching regardless of the API subscription key and the API Product which the key is associated with (i.e. any authenticated/authorized user making the exact same API request should be able to fetch the data from cache if the query string match).
Many thanks.
<policies>
<inbound>
<base />
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" allow-private-response-caching="false" must-revalidate="false" downstream-caching-type="none">
<vary-by-query-parameter>Id</vary-by-query-parameter>
<vary-by-query-parameter>dataType</vary-by-query-parameter>
<vary-by-query-parameter>pageNumber</vary-by-query-parameter>
</cache-lookup>
</inbound>
<backend>
<base />
</backend>
<outbound>
<redirect-content-urls />
<base />
<cache-store duration="600" />
</outbound>
<on-error>
<base />
</on-error>
</policies>