Compare commits

...

3 Commits

Author SHA1 Message Date
Barret Schloerke
f8a91fb2e3 Always disable UI cache (unless there's an existing Cache-Control header) 2023-04-18 21:34:18 -04:00
Barret Schloerke
7909389f0a Only disable cache if a theme has been set 2023-04-18 15:34:15 -04:00
Garrick Aden-Buie
596165e473 Set cache control headers to avoid caching UI 2023-04-18 12:22:31 -04:00

View File

@@ -231,11 +231,32 @@ uiHttpHandler <- function(ui, uiPattern = "^/$") {
if (is.null(uiValue))
return(NULL)
if (inherits(uiValue, "httpResponse")) {
return(uiValue)
} else {
# Avoid caching the UI response to ensure that UI is always re-evaluated.
# This is necessary for getCurrentTheme() to be known, required for BS4+.
no_cache_headers <- list(
"Cache-Control" = "no-cache, no-store, must-revalidate",
"Pragma" = "no-cache",
"Expires" = "0"
)
if (!inherits(uiValue, "httpResponse")) {
html <- renderPage(uiValue, showcaseMode, testMode)
return(httpResponse(200, content=html))
uiValue <- httpResponse(200, content=html)
}
# 2023-04-23 jcheng5: Example app in PR comment
# https://github.com/rstudio/shiny/pull/3810#issuecomment-1513828996
# > I think we should always add the cache-busting headers. Without it,
# Connect and ShinyApps.io configurations will have problems in that the
# workerId could be a stale value.
if (
# The user has not set a `Cache-Control` policy within their UI func
!"Cache-Control" %in% names(uiValue$headers)
) {
# Disable caching for the UI's response
uiValue$headers <- utils::modifyList(uiValue$headers, no_cache_headers)
}
uiValue
}
}