@@ -48,16 +48,26 @@ impl CachePolicy {
4848 CachePolicy :: NoStoreMustRevalidate => Some ( NO_STORE_MUST_REVALIDATE . clone ( ) ) ,
4949 CachePolicy :: ForeverInCdnAndBrowser => Some ( FOREVER_IN_CDN_AND_BROWSER . clone ( ) ) ,
5050 CachePolicy :: ForeverInCdn => {
51- // A missing `max-age` or `s-maxage` in the Cache-Control header will lead to
52- // CloudFront using the default TTL, while the browser not seeing any caching header.
53- // This means we can have the CDN caching the documentation while just
54- // issuing a purge after a build.
55- // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist
56- None
51+ if config. full_page_cache {
52+ // A missing `max-age` or `s-maxage` in the Cache-Control header will lead to
53+ // CloudFront using the default TTL, while the browser not seeing any caching header.
54+ // This means we can have the CDN caching the documentation while just
55+ // issuing a purge after a build.
56+ // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist
57+ None
58+ } else {
59+ Some ( NO_CACHING . clone ( ) )
60+ }
61+ }
62+ CachePolicy :: ForeverInCdnAndStaleInBrowser => {
63+ if config. full_page_cache {
64+ config
65+ . cache_control_stale_while_revalidate
66+ . map ( |seconds| format ! ( "stale-while-revalidate={seconds}" ) . parse ( ) . unwrap ( ) )
67+ } else {
68+ Some ( NO_CACHING . clone ( ) )
69+ }
5770 }
58- CachePolicy :: ForeverInCdnAndStaleInBrowser => config
59- . cache_control_stale_while_revalidate
60- . map ( |seconds| format ! ( "stale-while-revalidate={seconds}" ) . parse ( ) . unwrap ( ) ) ,
6171 }
6272 }
6373}
@@ -129,6 +139,7 @@ mod tests {
129139 Ok ( ( ) )
130140 } ) ;
131141 }
142+
132143 #[ test]
133144 fn render_stale_with_config ( ) {
134145 wrapper ( |env| {
@@ -145,4 +156,36 @@ mod tests {
145156 Ok ( ( ) )
146157 } ) ;
147158 }
159+
160+ #[ test]
161+ fn render_forever_in_cdn_disabled ( ) {
162+ wrapper ( |env| {
163+ env. override_config ( |config| {
164+ config. full_page_cache = false ;
165+ } ) ;
166+
167+ assert_eq ! (
168+ CachePolicy :: ForeverInCdn . render( & env. config( ) ) . unwrap( ) ,
169+ "max-age=0"
170+ ) ;
171+ Ok ( ( ) )
172+ } ) ;
173+ }
174+
175+ #[ test]
176+ fn render_forever_in_cdn_or_stale_disabled ( ) {
177+ wrapper ( |env| {
178+ env. override_config ( |config| {
179+ config. full_page_cache = false ;
180+ } ) ;
181+
182+ assert_eq ! (
183+ CachePolicy :: ForeverInCdnAndStaleInBrowser
184+ . render( & env. config( ) )
185+ . unwrap( ) ,
186+ "max-age=0"
187+ ) ;
188+ Ok ( ( ) )
189+ } ) ;
190+ }
148191}
0 commit comments