|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gargoylesoftware.htmlunit.Cache
public class Cache
Simple cache implementation which caches compiled JavaScript files and parsed CSS snippets. Caching compiled JavaScript files avoids unnecessary web requests and additional compilation overhead, while caching parsed CSS snippets avoids very expensive CSS parsing.
Constructor Summary | |
---|---|
Cache()
|
Method Summary | |
---|---|
void |
cache(String css,
org.w3c.dom.css.CSSStyleSheet styleSheet)
Caches the parsed version of the specified CSS snippet. |
void |
cacheIfPossible(WebRequest request,
WebResponse response,
Object toCache)
Caches the specified object, if the corresponding request and response objects indicate that it is cacheable. |
void |
clear()
Clears the cache. |
protected void |
deleteOverflow()
Truncates the cache to the maximal number of entries. |
Object |
getCachedObject(WebRequest request)
Returns the cached object corresponding to the specified request. |
org.w3c.dom.css.CSSStyleSheet |
getCachedStyleSheet(String css)
Returns the cached parsed version of the specified CSS snippet. |
int |
getMaxSize()
Returns the cache's maximum size. |
int |
getSize()
Returns the number of entries in the cache. |
protected boolean |
isCacheable(WebRequest request,
WebResponse response)
Determines if the specified response can be cached. |
protected boolean |
isDynamicContent(WebResponse response)
Tries to guess if the content is dynamic or not. |
protected boolean |
isJavaScript(WebResponse webResponse)
Returns true if the provided response is JavaScript content. |
protected Date |
parseDateHeader(WebResponse response,
String headerName)
Parses and returns the specified date header of the specified response. |
void |
setMaxSize(int maxSize)
Sets the cache's maximum size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Cache()
Method Detail |
---|
public void cacheIfPossible(WebRequest request, WebResponse response, Object toCache)
request
- the request corresponding to the specified compiled scriptresponse
- the response corresponding to the specified compiled scripttoCache
- the object that is to be cached, if possible (may be for instance a compiled script or
simply a WebResponse)public void cache(String css, org.w3c.dom.css.CSSStyleSheet styleSheet)
isDynamicContent(WebResponse)
), and headers often
aren't set up correctly, disallowing caching when in fact it should be allowed.
css
- the CSS snippet from which styleSheet is derivedstyleSheet
- the parsed version of cssprotected void deleteOverflow()
protected boolean isCacheable(WebRequest request, WebResponse response)
request
- the performed requestresponse
- the received response
true
if the response can be cachedprotected boolean isDynamicContent(WebResponse response)
Tries to guess if the content is dynamic or not.
"Since origin servers do not always provide explicit expiration times, HTTP caches typically assign heuristic expiration times, employing algorithms that use other header values (such as the Last-Modified time) to estimate a plausible expiration time".
The current implementation considers as dynamic content everything except responses with a Last-Modified header with a date older than 10 minutes or with an Expires header specifying expiration in more than 10 minutes.
response
- the response to examine
true
if the response should be considered as dynamic and therefore uncacheableprotected Date parseDateHeader(WebResponse response, String headerName)
response
- the responseheaderName
- the header name
protected boolean isJavaScript(WebResponse webResponse)
webResponse
- the response to analyze
true
if it can be considered as JavaScriptpublic Object getCachedObject(WebRequest request)
request
- the request whose corresponding cached compiled script is sought
public org.w3c.dom.css.CSSStyleSheet getCachedStyleSheet(String css)
css
- the CSS snippet whose cached stylesheet is sought
public int getMaxSize()
public void setMaxSize(int maxSize)
maxSize
- the cache's maximum size (must be >= 0)public int getSize()
public void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |