public class Cache extends Object implements Serializable
Simple cache implementation.
The current implementation's main purpose is to provide the ability to cache .js files.
Constructor and Description |
---|
Cache() |
Modifier and Type | Method and Description |
---|---|
void |
cacheIfNeeded(WebRequestSettings request,
WebResponse response)
Cache the response if needed.
|
protected void |
deleteOverflow()
Truncates the cache to the maximal number of entries.
|
WebResponse |
getCachedContent(WebRequestSettings request)
Returns the cached content corresponding to the specified request.
|
int |
getMaxSize()
Returns the cache's maximum size.
|
int |
getSize()
Returns the number of entries in the cache.
|
protected boolean |
isCacheable(WebRequestSettings request,
WebResponse response)
Determines if the response should be cached.
|
protected boolean |
isDynamicContent(WebResponse response)
Tries to guess if the content is dynamic or not.
|
protected boolean |
isJavaScript(WebResponse webResponse)
Indicates 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.
|
public void cacheIfNeeded(WebRequestSettings request, WebResponse response)
request
- the requestresponse
- the responseprotected void deleteOverflow()
protected boolean isCacheable(WebRequestSettings request, WebResponse response)
request
- the performed requestresponse
- the received responsetrue
if the response should 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.
protected Date parseDateHeader(WebResponse response, String headerName)
response
- the responseheaderName
- the header nameprotected boolean isJavaScript(WebResponse webResponse)
webResponse
- the response to analyzetrue
if it can be considered as JavaScriptpublic WebResponse getCachedContent(WebRequestSettings request)
request
- the request whose cached content is soughtpublic int getMaxSize()
public void setMaxSize(int maxSize)
maxSize
- the cache's maximum size (must be >= 0)public int getSize()
Copyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.