Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jowerner
Copy link
Contributor

  • 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
@jowerner jowerner linked an issue Jan 10, 2025 that may be closed by this pull request
final String dateValue = webResponse.getResponseHeaderValue(HttpHeaderConstants.DATE);
if (dateValue != null && dateValue.length() > 0)
{
final SimpleDateFormat dateParser = new SimpleDateFormat(HEADER_DATE_FORMAT, Locale.ENGLISH);
Copy link
Contributor

@h-arlt h-arlt Jan 10, 2025

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.

Copy link
Contributor

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
Copy link
Contributor

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));
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix caching and revalidation of expired resources
2 participants