YouTube API v3文档建议使用ETag以获得更好的性能:
Your application can cache API resources and their ETags. Then, when your application requests a stored resource again, it specifies the ETag associated with that resource. If the resource has changed, the API returns the modified resource and the ETag associated with that version of the resource. If the resource has not changed, the API returns an HTTP 304 response (Not Modified)
从Getting Started with the YouTube Data API\Optimizing performance\Using ETags
我的问题是如何使用.Net客户端库指定关联的ETag?
最佳答案
使用etags的一般想法是,请求在请求中添加一个“If-None-Match” header ,该 header 设置为etag的值。服务器已经配置为通过检查etag并响应304来响应该 header ,如果没有任何更改。因此,实际上,这取决于给定的客户端库是否支持添加自定义 header (例如“If-None-Match”),然后具有代码来处理304(如果返回的话)(或者是否替换其缓存)。 。
我知道YouTube javascript库确实可以做到(在构造gapi.client.request
对象时,您只是传递了具有附加 header 的“ header ”对象),但是从我对.Net客户端代码(https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.Core/Apis/Requests/RequestBuilder.cs)的粗浅阅读中,看来.Net客户端不允许您当前设置此 header 。您始终可以在客户端结构之外发出直接GET请求,或者扩展客户端以包括功能,只要您随后还处理了缓存部分。但是,我可能是错误的,并且输入了错误的代码。
关于c# - 如何在YouTube API v3的.Net客户端库中指定ETag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163321/