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 HTML, JSON, XML
} }
private Date date_cache_IfModifiedSince = null;
public RequestHeader() { public RequestHeader() {
super(); super();
} }
@ -86,8 +88,11 @@ public class RequestHeader extends HeaderFramework {
return url.getHost(); return url.getHost();
} }
public Date ifModifiedSince() { 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() { public Object ifRange() {

@ -38,6 +38,10 @@ public class ResponseHeader extends HeaderFramework {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
private static final ConcurrentLog log = new ConcurrentLog(ResponseHeader.class.getName()); 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) { public ResponseHeader(final int statusCode) {
super(); super();
this.put(HeaderFramework.STATUS_CODE, Integer.toString(statusCode)); this.put(HeaderFramework.STATUS_CODE, Integer.toString(statusCode));
@ -71,19 +75,25 @@ public class ResponseHeader extends HeaderFramework {
} }
public Date date() { public Date date() {
if (this.date_cache_Date != null) return this.date_cache_Date;
final Date d = headerDate(HeaderFramework.DATE); final Date d = headerDate(HeaderFramework.DATE);
final Date now = new 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() { 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() { 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(); 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() { public long age() {
@ -94,8 +104,8 @@ public class ResponseHeader extends HeaderFramework {
} }
public boolean gzip() { public boolean gzip() {
return ((containsKey(CONTENT_ENCODING)) && return ((containsKey(HeaderFramework.CONTENT_ENCODING)) &&
((get(CONTENT_ENCODING)).toUpperCase().startsWith("GZIP"))); ((get(HeaderFramework.CONTENT_ENCODING)).toUpperCase().startsWith("GZIP")));
} }
public static Object[] parseResponseLine(final String respLine) { public static Object[] parseResponseLine(final String respLine) {

Loading…
Cancel
Save