How to prevent same api calls

Prathamesh Shende 441 Reputation points
2021-12-17T12:59:02.42+00:00

HI,
I build the WebApp using Blazor Wasm and ASP.net Core WebApi.

I am calling the same on every page in blazor wasm. Due to this api taking time to load and took time display called data into razor page.
I also optimized the api and database and also memoryCache in API . it improve the performance no doubt.

But for that I m still making the API call for MemoryCache Data. What is the best practices to call the data and reduces the unnecessary API Calls ?

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Blazor
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2021-12-17T13:51:26.137+00:00

    Blazor has state management APIs. The official documentation covers the details.

    ASP.NET Core Blazor state management

    I assume you want to cache data in the browser.

    Browser storage

    0 comments No comments

  2. Adam Jachocki 46 Reputation points
    2021-12-17T14:41:01.86+00:00

    You can also create a component, call this api insinde this component, and then call this component inside your other parts of site, for example:

    <MyComponentWhichCallApi>

    <RestOfTheSite />

    </MyComponentWhichCallApi>

    0 comments No comments

  3. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-12-17T16:26:52.99+00:00

    You can also use a service worker to do this. This is one of the main use cases of service workers, caching api responses.

    Most likely your project already has a service-worker.js file, but if not see

    https://learn.microsoft.com/en-us/aspnet/core/blazor/progressive-web-app?view=aspnetcore-6.0&tabs=visual-studio


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.