Class WebResponse
java.lang.Object
org.frontcache.core.WebResponse
- All Implemented Interfaces:
Serializable
Container for web response. Usually it's text response for GET method.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionWebResponse(String url) some responses has no body (e.g.WebResponse(String url, byte[] content) maxAgeStr = null so, content is not subject to cache (maxAge = 0/no_cache)WebResponse(String url, byte[] content, String maxAgeStr, String refreshType) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddTags(Collection<String> tags) copy()A shallow copy: the contentbyte[]is SHARED, not cloned.byte[]longcontent length in byteslongEffective expiration timestamp (epoch millis) of this response across all client types.intgetTags()getUrl()booleanCheck if response is cacheablebooleanisText()voidsetCacheLevel(String cacheLevel) voidsetContent(byte[] content) voidsetExpireTimeMap(Map<String, Long> expireTimeMap) voidsetHeaders(Map<String, List<String>> headers) voidsetRefreshType(String refreshType) voidsetStatusCode(int statusCode) voidvoid
-
Constructor Details
-
WebResponse
public WebResponse() -
WebResponse
some responses has no body (e.g. response for redirect) maxAgeStr = null so, content is not subject to cache (maxAge = 0/no_cache)- Parameters:
url-
-
WebResponse
maxAgeStr = null so, content is not subject to cache (maxAge = 0/no_cache)- Parameters:
url-content-
-
WebResponse
-
-
Method Details
-
getStatusCode
public int getStatusCode() -
setStatusCode
public void setStatusCode(int statusCode) -
getUrl
-
setUrl
-
getHeaders
-
getHeader
-
isText
public boolean isText() -
setHeaders
-
getTags
-
setTags
-
addTags
- Parameters:
tags-
-
getContent
public byte[] getContent()- Returns:
-
setContent
public void setContent(byte[] content) - Parameters:
content-
-
isCacheable
public boolean isCacheable()Check if response is cacheable- Returns:
-
getContentLenth
public long getContentLenth()content length in bytes- Returns:
-
addHeader
-
copy
A shallow copy: the contentbyte[]is SHARED, not cloned. That is deliberate and is what keeps a cache hit from duplicating the whole page - the copy exists so thatputToCache's in-place header strip, and the response headers a caller adds, do not reach the instance held in the cache. Two things here were wrong rather than merely slow, and both are fixed:- the header map came back as a plain
HashMap. Every map built byFCUtils.revertHeadersis aTreeMap(String.CASE_INSENSITIVE_ORDER), because header names are case-insensitive (RFC 7230) and intermediaries re-case them - so copying into a HashMap silently made the copy case-SENSITIVE, and a re-casedContent-Typestopped resolving on it. The comparator is preserved now; - it routed through
new WebResponse(url, content), whose constructor callssetExpireTime(null)- a trim, fourendsWithchecks and anInteger.parseIntinFCUtils.maxAgeStr2Int(String)- to populate an expireTimeMap that the very next line overwrote. This runs on every cache hit.
- the header map came back as a plain
-
getExpireTimeMillis
public long getExpireTimeMillis()Effective expiration timestamp (epoch millis) of this response across all client types. Used for time-based purging of stale entries. An entry that is still serveable to bots until T1 and to guests until T2 is fully expired only after max(T1, T2), so the latest expiration wins.- Returns:
- CACHE_FOREVER (-1) if the response never expires; NO_CACHE (0) if it is not cacheable for any client type; otherwise the latest expiration timestamp among client types.
-
getExpireTimeMap
-
setExpireTimeMap
-
getRefreshType
-
setRefreshType
-
getCacheLevel
-
setCacheLevel
-