5.18Disabling HTTP Caching

Updated on Aug 20, 2026~3 min read

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.

cs
// 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:

bash
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, disabling HTTP caching.
    • new(disabled): applies to a method or interface, setting whether to disable HTTP caching.
  • Properties:

    • Disabled: whether to disable (bool type); the default value is true (disabled).