@@ -103,6 +103,7 @@ async fn main() {
103
103
. route_with_tsr ( "/ping/:edition/:hostname" , get ( ping_page) )
104
104
. route ( "/internal/ping-frame/:edition/:hostname" , get ( ping_frame) )
105
105
. route ( "/internal/ping-markup/:edition/:hostname" , get ( ping_markup) )
106
+ . layer ( axum:: middleware:: from_fn ( cache_short) )
106
107
. fallback_service ( serve_dir)
107
108
. layer ( axum:: middleware:: from_fn ( csp) )
108
109
. with_state ( state) ;
@@ -127,6 +128,8 @@ static ROBOTS_NAME: HeaderName = HeaderName::from_static("x-robots-tag");
127
128
static ROBOTS_VALUE : HeaderValue = HeaderValue :: from_static ( "noindex" ) ;
128
129
static CACHE_CONTROL_IMMUTABLE : HeaderValue =
129
130
HeaderValue :: from_static ( "immutable, public, max-age=31536000" ) ;
131
+ static CACHE_CONTROL_SHORT : HeaderValue =
132
+ HeaderValue :: from_static ( "max-age=30, public, stale-while-revalidate" ) ;
130
133
131
134
static CSP_VALUE : HeaderValue = HeaderValue :: from_static (
132
135
"default-src 'self'; \
@@ -160,6 +163,13 @@ async fn cache(req: Request, next: Next) -> Response {
160
163
resp
161
164
}
162
165
166
+ async fn cache_short ( req : Request , next : Next ) -> Response {
167
+ let mut resp = next. run ( req) . await ;
168
+ resp. headers_mut ( )
169
+ . insert ( CACHE_CONTROL , CACHE_CONTROL_SHORT . clone ( ) ) ;
170
+ resp
171
+ }
172
+
163
173
#[ derive( Template ) ]
164
174
#[ template( path = "index.html" ) ]
165
175
pub struct RootTemplate {
0 commit comments