I need to consume a costly API using C#, I would like to create mechanisms that log and notify or just take action to avoid undesired calls to the API. I imagine something similar to the circuit breaker pattern but for consuming resources such as an API. A pattern, Azure technology, library, or architecture guide would work I just don’t want to reinvent the wheel.
CodePudding user response:
Several API's exist for implementing rate limiting. Microsoft recently introduced this one: https://devblogs.microsoft.com/dotnet/announcing-rate-limiting-for-dotnet/)
Depending on your application you may want to cache existing requests data so they can be returned to your application when necessary and rate limiting is preventing more calls. For that you can use any number of caching strategies including Microsofts MemoryCache - https://learn.microsoft.com/en-us/dotnet/api/system.runtime.caching.memorycache?view=dotnet-plat-ext-6.0 or something similar.