C#C
C#2y ago
nox7

Mutex? ASP Core - Only Allowing a Method to Be Run One at a Time

I have a scenario where I want all requests to an endpoint to have the ability to only be run one at a time. This method is asynchronous.

The situation: When a client of ours logs into their dashboard, it shows a "marketing tips" blog section which pulls blog articles from a 3rd party. However, I don't need every request to hit the 3rd party list API for those articles - every client will see the same article.

I want the HTTP request to list and cache those articles to only ever be running one at a time. In essence
  • If blogs need to be fetched from third party, do not let other processes run this request
  • Else, let processes run this request as often as they want (it will get the blogs from a local cache in this case)
Will a Mutex work for this case?
Was this page helpful?