[Azure Search] Support cleaning cache for Azure Search Client
See original GitHub issueMy customer wants to have a feature to clear the cache of the Azure Search.
My customer encounter the shortage of Azure Search. Azure Search had a shortage however, it successfully fail over to change the DNS. However, the client side, they cache Azure Search Client, and there is no way to clear cache. Azure Functions recommend to make Client Static. For the standard API of the Client, we can pass the HttpClientHandler instance to the client. However not for SocketsHttpHandler which support cleaning DNS cache.
We ended up with use refrection to inject the DNS cache configuration. This might be mandatory to support the fail over.
This is our current work around.
public class KeepAliveAvailableHttpClientHandler : HttpClientHandler
{
private readonly FieldInfo _fieldInfo =
typeof(HttpClientHandler).GetField("_socketsHttpHandler", BindingFlags.NonPublic | BindingFlags.Instance);
public KeepAliveAvailableHttpClientHandler()
{
var socketHttpHandler = (SocketsHttpHandler) _fieldInfo.GetValue(this);
socketHttpHandler.PooledConnectionIdleTimeout = TimeSpan.FromMinutes(3);
socketHttpHandler.PooledConnectionLifetime = TimeSpan.FromMinutes(1);
}
}
pass it.
var handler = new KeepAliveAvailableHttpClientHandler();
indexClient = new SearchIndexClient(searchServiceName, "azuresql-index", new SearchCredentials(adminApiKey), handler , null);
For more detail, I wrote a blog about it.
https://medium.com/@tsuyoshiushio/cleaning-dns-cache-with-azure-search-client-14cbd73d8195
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
Adding @alexghiondea and @weshaggard since they are handling data plane-related requirements for the Azure .NET SDKs going forward.
@TsuyoshiUshio I haven’t heard from you, so I’m closing this issue. Please let me know if you have a reason to re-open it.