added date parser caches to prevent re-calculation of costly date

parsing
pull/1/head
Michael Peter Christen 11 years ago
parent 552ef9f18e
commit ef7ddbc933

@ -58,6 +58,8 @@ public class RequestHeader extends HeaderFramework {
HTML, JSON, XML
}
private Date date_cache_IfModifiedSince = null;
public RequestHeader() {
super();
}
@ -86,8 +88,11 @@ public class RequestHeader extends HeaderFramework {
return url.getHost();
}
public Date ifModifiedSince() {
return headerDate(IF_MODIFIED_SINCE);
if (this.date_cache_IfModifiedSince != null) return date_cache_IfModifiedSince;
this.date_cache_IfModifiedSince = headerDate(RequestHeader.IF_MODIFIED_SINCE);
return this.date_cache_IfModifiedSince;
}
public Object ifRange() {

@ -38,6 +38,10 @@ public class ResponseHeader extends HeaderFramework {
private static final long serialVersionUID = 0L;
private static final ConcurrentLog log = new ConcurrentLog(ResponseHeader.class.getName());
private Date date_cache_Date = null;
private Date date_cache_Expires = null;
private Date date_cache_LastModified = null;
public ResponseHeader(final int statusCode) {
super();
this.put(HeaderFramework.STATUS_CODE, Integer.toString(statusCode));
@ -69,21 +73,27 @@ public class ResponseHeader extends HeaderFramework {
return 200;
}
}
public Date date() {
if (this.date_cache_Date != null) return this.date_cache_Date;
final Date d = headerDate(HeaderFramework.DATE);
final Date now = new Date();
return (d == null) ? now : d.after(now) ? now : d;
this.date_cache_Date = (d == null) ? now : d.after(now) ? now : d;
return this.date_cache_Date;
}
public Date expires() {
return headerDate(EXPIRES);
if (this.date_cache_Expires != null) return this.date_cache_Expires;
this.date_cache_Expires = headerDate(HeaderFramework.EXPIRES);
return this.date_cache_Expires;
}
public Date lastModified() {
final Date d = headerDate(LAST_MODIFIED);
if (this.date_cache_LastModified != null) return this.date_cache_LastModified;
final Date d = headerDate(HeaderFramework.LAST_MODIFIED);
final Date now = new Date();
return (d == null) ? date() : d.after(now) ? now : d;
this.date_cache_LastModified = (d == null) ? date() : d.after(now) ? now : d;
return this.date_cache_LastModified;
}
public long age() {
@ -94,8 +104,8 @@ public class ResponseHeader extends HeaderFramework {
}
public boolean gzip() {
return ((containsKey(CONTENT_ENCODING)) &&
((get(CONTENT_ENCODING)).toUpperCase().startsWith("GZIP")));
return ((containsKey(HeaderFramework.CONTENT_ENCODING)) &&
((get(HeaderFramework.CONTENT_ENCODING)).toUpperCase().startsWith("GZIP")));
}
public static Object[] parseResponseLine(final String respLine) {

Loading…
Cancel
Save