CodexBloom - Programming Q&A Platform

Azure API Management Caching optimization guide as Expected in .NET Core Application

👀 Views: 1 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-11
azure-api-management caching aspnet-core C#

I'm trying to implement I'm experimenting with This might be a silly question, but I'm sure I'm missing something obvious here, but I'm currently working with an scenario with Azure API Management where the caching policy doesn't seem to apply to my .NET Core backend service... I've set up a simple GET endpoint in my ASP.NET Core Web API that returns a list of users from a database. I have integrated API Management with this endpoint and configured a caching policy that is supposed to cache the response for 10 minutes. However, I still see that every request hits the backend service, which leads to performance optimization. Here's a snippet of the policy I'm using in Azure API Management: ```xml <inbound> <base /> <cache-lookup vary-by-developer="false" vary-by-developer-groups="false" vary-by-developer-group="false" vary-by-header="" vary-by-query-parameter="" /> </inbound> <backend> <base /> </backend> <outbound> <base /> <cache-store duration="600" /> </outbound> ``` I've double-checked that the caching policy is applied correctly to the correct API and operation in Azure API Management. The scenario continues even after I tried clearing the cache manually via the Azure portal. My backend service is running on .NET Core 5.0, and I'm using the latest version of Azure API Management. I've also reviewed the logs and didn't see any errors related to caching. I expected that after the first request, subsequent calls would return the cached result, but they all end up hitting the database every time. I've also verified that the backend response is not being cached either by adding a simple delay in my controller action to simulate heavy load: ```csharp [HttpGet] public async Task<IActionResult> GetUsers() { await Task.Delay(5000); // Simulate database access delay var users = await _userService.GetAllUsersAsync(); return Ok(users); } ``` Despite this delay, I still observe that the performance is not improving. Is there a specific configuration I might be missing, or is there a best practice I should follow to ensure that caching works properly in this scenario? Has anyone else encountered this? Thanks in advance! I'm working with C# in a Docker container on Linux. What's the best practice here? I'm working with C# in a Docker container on CentOS.