@@ -43,15 +43,11 @@ export default async (req, res) => {
4343const stats = await fetchWakatimeStats ( { username, api_domain, range} ) ;
4444
4545let cacheSeconds = clampValue (
46- parseInt ( cache_seconds || CONSTANTS . FOUR_HOURS , 10 ) ,
46+ parseInt ( cache_seconds || CONSTANTS . CARD_CACHE_SECONDS , 10 ) ,
4747CONSTANTS . FOUR_HOURS ,
4848CONSTANTS . ONE_DAY ,
4949) ;
5050
51- if ( ! cache_seconds ) {
52- cacheSeconds = CONSTANTS . FOUR_HOURS ;
53- }
54-
5551res . setHeader (
5652"Cache-Control" ,
5753`max-age=${
@@ -80,7 +76,12 @@ export default async (req, res) => {
8076} ) ,
8177) ;
8278} catch ( err ) {
83- res . setHeader ( "Cache-Control" , `no-cache, no-store, must-revalidate` ) ; // Don't cache error responses.
79+ res . setHeader (
80+ "Cache-Control" ,
81+ `max-age=${ CONSTANTS . ERROR_CACHE_SECONDS / 2 } , s-maxage=${
82+ CONSTANTS . ERROR_CACHE_SECONDS
83+ } , stale-while-revalidate=${ CONSTANTS . ONE_DAY } `,
84+ ) ; // Cache the error response less frequently.
8485return res . send ( renderError ( err . message , err . secondaryMessage ) ) ;
8586}
8687} ;