5.18Disabling HTTP Caching
When sending an HTTP GET request, the server may cache the result of that request to improve performance. To cancel its caching behavior, you can add the DisableCacheAttribute attribute.
HTTP declarative requests disable HTTP caching via the DisableCacheAttribute attribute. The corresponding HTTP declarative extractor is implemented as the DisableCacheDeclarativeExtractor type, which is responsible for parsing the DisableCacheAttribute attribute and building the HttpRequestBuilder instance configuration required to disable HTTP caching.
// Apply on the interface definition, affecting all methods[DisableCache]public interface IHttpService : IHttpDeclarative{ // Apply on a method [DisableCache] [Get("https://furion.net/")] Task<string> GetStringAsync(); [DisableCache(false)] // Enable caching (default) [Get("https://furion.net/")] Task<string> GetStringAsync();}After adding this attribute, the HTTP request will automatically attach the following request headers before sending to ensure cache control:
Cache-Control: must-revalidate, no-cache, no-storePragma: no-cacheIf-None-Match: ""DisableCacheAttribute includes the following constructors and properties:
-
Constructors:
new(): applies to a method or interface, disablingHTTPcaching.new(disabled): applies to a method or interface, setting whether to disableHTTPcaching.
-
Properties:
Disabled: whether to disable (booltype); the default value istrue(disabled).