ice.net
Class CachedObject

java.lang.Object
  extended byice.net.CachedObject
All Implemented Interfaces:
Serializable

public class CachedObject
extends Object
implements Serializable

This class represents a cached object.

For more complete information about Caching in HTTP, please refer to the following:

Since:
1.4.1
Version:
1.6.0
Author:
Thomas Nøkleby, Jack van Ooststroom
See Also:
CacheManager, Serialized Form

Constructor Summary
CachedObject(CacheManager cacheManager)
          Constructs a CachedObject with the specified cacheManager.
CachedObject(HttpResponse httpResponse, CacheManager cacheManager)
          Constructs a CachedObject with the specified httpResponse and cacheManager.
CachedObject(HttpResponse httpResponse, ice.net.HttpSession httpSession)
          Deprecated. As of 1.6.0.
CachedObject(ice.net.HttpSession httpSession)
          Deprecated. As of 1.5.0, replaced by CachedObject(CacheManager).
 
Method Summary
static long calculateCurrentAge(long ageValue, long dateValue, long requestTime, long responseTime)
          Calculates the current age of this CachedObject.
static long calculateFreshnessLifetime(long maxAgeValue, long expiresValue, long dateValue, long lastModifiedValue, long responseTime, long cacheExpirationBuffer)
          Calculates the freshness lifetime of this CachedObject.
 long getAge()
          Gets the age HTTP header field value in milliseconds of this CachedObject's HttpResponse.
 byte[] getdata()
          Deprecated. As of 1.6.0, replaced by getResponse().getEntityBody().getBytes().
 long getDate()
          Gets the date HTTP header field value in milliseconds of this CachedObject's HttpResponse.
 long getExpires()
          Gets the expires HTTP header field value in milliseconds of this CachedObject's HttpResponse.
 String[] getHeaderKeys()
          Gets all the HTTP header field names of this CachedObject's HttpResponse.
 String[] getHeaders()
          Gets all the HTTP header field values of this CachedObject's HttpResponse.
 long getLastAccessed()
          Gets last accessed time in milliseconds of this CachedObject.
 long getLastModified()
          Gets the last modified HTTP header field value in milliseconds of this CachedObject's HttpResponse.
 long getMaxAge()
          Gets the max-age cache directive of the Cache-Control HTTP header field value of this CachedObject's HttpResponse.
 long getRecivedAt()
          Deprecated. As of 1.6.0, replaced by getResponse().getResponseTime().
 long getRequestTime()
          Gets the request time in milliseconds of the HttpRequest that resulted in this CachedObject's HttpResponse.
 HttpResponse getResponse()
          Gets the HTTP response of this CachedObject.
 String getURL()
          Gets the URL of this CachedObject.
 boolean isFresh()
          Determines if this CachedObject is fresh.
static boolean isFresh(long ageValue, long dateValue, long requestTime, long responseTime, long maxAgeValue, long expiresValue, long lastModifiedValue, long cacheExpirationBuffer)
          Determines based upon the specified values if some response is fresh.
 void setExpires(long expiresValue)
          Convenience method for setting the Expires field value of the containing HttpResponse to the specified expiresValue.
 void setLastAccessed(long lastAccessed)
          Sets last accessed time in milliseconds of this CachedObject to the specified lastAccessed.
 void setRequestTime(long requestTime)
          Sets the request time in milliseconds of the HttpRequest that resulted in this CachedObject's HttpResponse to the specified requestTime.
 void setResponse(HttpResponse httpResponse)
          Sets the HTTP response of this CachedObject to the specified httpResponse.
 void setURL(String url)
          Sets the URL of this CachedObject to the specified url.
 int size()
          Gets the approximate size in number of bytes of this CachedObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedObject

public CachedObject(HttpResponse httpResponse,
                    CacheManager cacheManager)

Constructs a CachedObject with the specified httpResponse and cacheManager.

Parameters:
httpResponse - the HTTP response of the CachedObject to be created.
cacheManager - the cache manager of the CachedObject to be created.
Since:
1.6.0

CachedObject

public CachedObject(CacheManager cacheManager)

Constructs a CachedObject with the specified cacheManager.

Parameters:
cacheManager - the cache manager of the CachedObject to be created.
Since:
1.5.0
See Also:
CachedObject(HttpResponse, CacheManager)

CachedObject

public CachedObject(HttpResponse httpResponse,
                    ice.net.HttpSession httpSession)
Deprecated. As of 1.6.0.


CachedObject

public CachedObject(ice.net.HttpSession httpSession)
Deprecated. As of 1.5.0, replaced by CachedObject(CacheManager).

Method Detail

calculateCurrentAge

public static long calculateCurrentAge(long ageValue,
                                       long dateValue,
                                       long requestTime,
                                       long responseTime)

Calculates the current age of this CachedObject.

Summary of the current age calculation algorithm:

     Legend:
     - age_value     : is the value of Age header received by the cache
                       with this response.
     - date_value    : is the value of the origin server's Date header.
     - request_time  : is the (local) time when the cache made the request
                       that resulted in this cached response.
     - response_time : is the (local) time when the cache received the
                       response.
     - now           : is the current (local) time.

     apparent_age           = max(0, response_time - date_value);
     corrected_received_age = max(apparent_age, age_value);
     response_delay         = response_time - request_time;
     corrected_initial_age  = corrected_received_age + response_delay;
     resident_time          = now - response_time;
     current_age            = corrected_initial_age + resident_time;
   

For more complete information about current age calculation, please refer to RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", section 13.2.3 - "Age Calculations".

Parameters:
ageValue - the Age HTTP header field value in a response represented in milliseconds.
dateValue - the Date HTTP header field value in a response represented in milliseconds.
requestTime - the request time in milliseconds.
responseTime - the response time in milliseconds.
Returns:
the calculated current age.
Since:
1.6.0

calculateFreshnessLifetime

public static long calculateFreshnessLifetime(long maxAgeValue,
                                              long expiresValue,
                                              long dateValue,
                                              long lastModifiedValue,
                                              long responseTime,
                                              long cacheExpirationBuffer)

Calculates the freshness lifetime of this CachedObject.

For more complete information about freshness lifetime calculation, please refer to RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", section 13.2.4 - "Expiration Calculation".

Parameters:
maxAgeValue - the max-age directive of the Cache-Control HTTP header field value in a response represented in milliseconds.
expiresValue - the Expires HTTP header field value in a response represented in milliseconds.
dateValue - the Date HTTP header field value in a response represented in milliseconds.
lastModifiedValue - the Last-Modified HTTP header field value in a response represented in milliseconds.
responseTime - the response time in milliseconds.
cacheExpirationBuffer - the cache expiration buffer in milliseconds.
Returns:
the calculated freshness lifetime.
Since:
1.6.0
See Also:
HttpResponse.MAX_AGE, HttpMessage.CACHE_CONTROL, HttpResponse.EntityBody#EXPIRES, HttpMessage.DATE, HttpResponse.EntityBody#LAST_MODIFIED

getAge

public long getAge()

Gets the age HTTP header field value in milliseconds of this CachedObject's HttpResponse.

Returns:
the age HTTP header field value in milliseconds.
Since:
1.6.0
See Also:
HttpResponse.AGE

getdata

public byte[] getdata()
Deprecated. As of 1.6.0, replaced by getResponse().getEntityBody().getBytes().


getDate

public long getDate()

Gets the date HTTP header field value in milliseconds of this CachedObject's HttpResponse.

Returns:
the date HTTP header field value in milliseconds.
Since:
1.6.0
See Also:
HttpMessage.DATE

getExpires

public long getExpires()

Gets the expires HTTP header field value in milliseconds of this CachedObject's HttpResponse.

Returns:
the expires HTTP header field value in milliseconds.
Since:
1.4.1
See Also:
HttpMessage.EntityBody.EXPIRES

getHeaderKeys

public String[] getHeaderKeys()

Gets all the HTTP header field names of this CachedObject's HttpResponse.

Returns:
the HTTP header field names.
Since:
1.4.1

getHeaders

public String[] getHeaders()

Gets all the HTTP header field values of this CachedObject's HttpResponse.

Returns:
the HTTP header field values.
Since:
1.4.1

getLastAccessed

public long getLastAccessed()

Gets last accessed time in milliseconds of this CachedObject.

Returns:
the last accessed time in milliseconds.
Since:
1.6.0
See Also:
setLastAccessed(long)

getLastModified

public long getLastModified()

Gets the last modified HTTP header field value in milliseconds of this CachedObject's HttpResponse.

Returns:
the last modified HTTP header field value in milliseconds.
Since:
1.4.1
See Also:
HttpMessage.EntityBody.LAST_MODIFIED

getMaxAge

public long getMaxAge()

Gets the max-age cache directive of the Cache-Control HTTP header field value of this CachedObject's HttpResponse.

Returns:
the max-age cache directive of the Cache-Control HTTP header field value.
Since:
1.4.1
See Also:
HttpMessage.CACHE_CONTROL, HttpResponse.MAX_AGE

getRecivedAt

public long getRecivedAt()
Deprecated. As of 1.6.0, replaced by getResponse().getResponseTime().


getRequestTime

public long getRequestTime()

Gets the request time in milliseconds of the HttpRequest that resulted in this CachedObject's HttpResponse.

That is, the time in milliseconds the HttpRequest was send.

Returns:
the request time in milliseconds.
Since:
1.6.0
See Also:
setRequestTime(long)

getResponse

public HttpResponse getResponse()

Gets the HTTP response of this CachedObject.

Returns:
the HTTP response.
Since:
1.6.0
See Also:
setResponse(HttpResponse)

getURL

public String getURL()

Gets the URL of this CachedObject.

Returns:
the URL.
Since:
1.4.1
See Also:
setURL(String)

isFresh

public boolean isFresh()

Determines if this CachedObject is fresh.

The calculation to determine if a response has expired is quite simple:

     response_is_fresh = (freshness_lifetime > current_age);
   

For more complete information about is fresh calculation, please refer to RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", section 13.2.4 - "Expiration Calculation".

Returns:
true is this CachedObject is fresh, false if not.
Since:
1.6.0
See Also:
isFresh(long, long, long, long, long, long, long, long)

isFresh

public static boolean isFresh(long ageValue,
                              long dateValue,
                              long requestTime,
                              long responseTime,
                              long maxAgeValue,
                              long expiresValue,
                              long lastModifiedValue,
                              long cacheExpirationBuffer)

Determines based upon the specified values if some response is fresh.

The calculation to determine if a response has expired is quite simple:

     response_is_fresh = (freshness_lifetime > current_age);
   

For more complete information about is fresh calculation, please refer to RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", section 13.2.4 - "Expiration Calculation".

Parameters:
ageValue - the Age HTTP header field value in a response represented in milliseconds.
dateValue - the Date HTTP header field value in a response represented in milliseconds.
requestTime - the request time in milliseconds.
responseTime - the response time in milliseconds.
maxAgeValue - the max-age directive of the Cache-Control HTTP header field value in a response represented in milliseconds.
expiresValue - the Expires HTTP header field value in a response represented in milliseconds.
lastModifiedValue - the Last-Modified HTTP header field value in a response represented in milliseconds.
cacheExpirationBuffer - the cache expiration buffer in milliseconds.
Returns:
true if based upon the specified values the result is fresh, false if not.
Since:
1.6.0
See Also:
calculateFreshnessLifetime(long, long, long, long, long, long), calculateCurrentAge(long, long, long, long)

setExpires

public void setExpires(long expiresValue)

Convenience method for setting the Expires field value of the containing HttpResponse to the specified expiresValue.

Parameters:
expiresValue - the new Expires value.
Since:
1.6.0
See Also:
getExpires()

setLastAccessed

public void setLastAccessed(long lastAccessed)

Sets last accessed time in milliseconds of this CachedObject to the specified lastAccessed.

Parameters:
lastAccessed - the new last accessed time in milliseconds.
Since:
1.6.0
See Also:
getLastAccessed()

setRequestTime

public void setRequestTime(long requestTime)

Sets the request time in milliseconds of the HttpRequest that resulted in this CachedObject's HttpResponse to the specified requestTime.

That is, the time in milliseconds the HttpRequest was send.

Parameters:
requestTime - the new request time in milliseconds.
Since:
1.6.0
See Also:
getRequestTime()

setResponse

public void setResponse(HttpResponse httpResponse)

Sets the HTTP response of this CachedObject to the specified httpResponse.

Parameters:
httpResponse - the new HTTP response.
Since:
1.6.0
See Also:
getResponse()

setURL

public void setURL(String url)

Sets the URL of this CachedObject to the specified url.

Parameters:
url - the new URL.
Since:
1.6.0
See Also:
getURL()

size

public int size()

Gets the approximate size in number of bytes of this CachedObject.

Returns:
the approximate size in number of bytes.
Since:
1.6.0