<cache-store>not hounouring the duration of clearing the external cache

Sruthi Varghese 0 Reputation points
2023-06-22T09:55:51.47+00:00

Hi,

I am trying to cache something in Azure redis for 30sec. but it is not clearing even after that.

This is my code snippet

<policies>
    <inbound>
        <base />
        <!-- Cache Lookup -->
        <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" allow-private-response-caching="true" must-revalidate="true" downstream-caching-type="none" caching-type="external">
            <vary-by-query-parameter>emailaddress</vary-by-query-parameter>
        </cache-lookup>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
        <!-- Cache Store -->
        <cache-store duration="30" />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,818 questions
Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
222 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,246 Reputation points
    2023-06-23T15:20:39.91+00:00

    Sruthi Varghese Thanks for posting your question in Microsoft Q&A. Does your backend response contain cache headers such as Cache-Control? If so, this might be as per design.

    Can you try the following code snippet (simple way to always use duration)?

    <policies>
        <inbound>
            <base />
            <!-- Cache Lookup -->
            <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" allow-private-response-caching="true" must-revalidate="true" downstream-caching-type="none" caching-type="external">
                <vary-by-query-parameter>emailaddress</vary-by-query-parameter>
            </cache-lookup>
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
    		<set-header name="Cache-Control" exists-action="delete" />
            <!-- Cache Store -->
            <cache-store duration="30" />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>
    

    If the backend response doesn't have cache headers, then duration should work as expected. If the backend response contains cache headers, whatever the higher value (duration from policy or response header expiration) would be applied.

    I hope this helps and let me know if you have any questions.

    1 person found this answer helpful.