public static void setCachingHeaders ( int maxAge , boolean publicScope , long lastModified , PortletResourceOutputHandler portletResourceOutputHandler ) { if ( maxAge != 0 ) { portletResourceOutputHandler . setDateHeader ( "Last-Modified" , lastModified ) ; if ( publicScope ) { portletResourceOutputHandler . setHeader ( "CacheControl" , "public" ) ; } else { portletResourceOutputHandler . setHeader ( "CacheControl" , "private" ) ; } if ( maxAge < 0 ) { // If caching "forever" set expires and max-age to 1 year maxAge = YEAR_OF_SECONDS ; } portletResourceOutputHandler . setDateHeader ( "Expires" , System . currentTimeMillis ( ) + TimeUnit . SECONDS . toMillis ( maxAge ) ) ; portletResourceOutputHandler . addHeader ( "CacheControl" , "max-age=" + maxAge ) ; } }
Set the Last - Modified CacheControl and Expires headers based on the maxAge publicScope and lastModified .