javascripthtmlbrowser-cachedonut-caching

Selective browser caching (ie donut) based on html tag/other no ASP?



Solution

  • From what I can tell, "donut hole caching" in ASP refers to server-side caching. The server re-uses, verbatim, the "bread" part of the donut across requests and re-generates the "hole" part for each request.

    The client (browser) has no such mechanism to differentiate the "bread" from the "hole". It caches at the request level, based on the cache headers sent by the server. So if the cache time-to-live for https://example.com/page-with-form is ten minutes, but the form's random ID is only valid for one minute, the user is likely to encounter an error, even if they refresh the page at nine minutes and 59 seconds.

    Keep in mind, the user may also encounter an error if they walk away for an hour, return, and hit "submit" on the form.

    One approach would be to disable client-side caching by setting no-cache headers on the server response.

    Another would be to allow caching of the HTML, but use JS to re-populate the random ID on an occasional basis (I don't know the security structure of your app, so I don't know if that defeats the purpose of the random ID).