-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#543: Fix caching and revalidation of expired resources #549
base: develop
Are you sure you want to change the base?
Conversation
jowerner
commented
Jan 10, 2025
- cache responses even if they are marked with "no-cache" or are already expired (they will be revalidated before next use)
- fixed calculation of expiration time
- adjusted test cases accordingly
…ady expired (they will be revalidated before next use) * fixed calculation of expiration time * adjusted test cases accordingly
final String dateValue = webResponse.getResponseHeaderValue(HttpHeaderConstants.DATE); | ||
if (dateValue != null && dateValue.length() > 0) | ||
{ | ||
final SimpleDateFormat dateParser = new SimpleDateFormat(HEADER_DATE_FORMAT, Locale.ENGLISH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential optimization: Create date formatter only once and make it a class constant. Formatter can also be re-used in lines 194, 220.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low: We may take this opportunity to replace all hard-coded HTTP header names w/ the proper constant values defined in HttpHeaderConstants.
@@ -164,36 +154,35 @@ public void testExpires_CacheControlMustRevalidate() throws Exception | |||
public void testExpires_CacheControlPublic_MaxAge() throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Isn't this the same as testExpires_CacheControlMaxAge
? AFAIK there is no distinction between private and public.
@@ -204,7 +193,7 @@ public void testExpires_NoCachingHints() throws Exception | |||
Assert.assertEquals(0, time); | |||
} | |||
|
|||
private String formatDate(final long time) | |||
private static String formatDate(final long time) | |||
{ | |||
return new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH).format(new Date(time)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse date formatter of CachingHttpWebConnection once it declares such a constant?