cachefilter.java
来自「oscache-2.4.1-full」· Java 代码 · 共 783 行 · 第 1/3 页
JAVA
783 行
/**
* <b>max-age</b> - defines the cache control response header max-age. Acceptable values are
* <code>MAX_AGE_NO_INIT</code> for don't initializing the max-age cache control,
* <code>MAX_AGE_TIME</code> the max-age information will be based on the time parameter and creation time of the content (expiration timestamp minus current timestamp), and
* <code>[positive integer]</code> value constant in seconds to be set in every response, the default value is 60.
*
* @param cacheControlMaxAge the cacheControlMaxAge to set
* @since 2.4
*/
public void setCacheControlMaxAge(long cacheControlMaxAge) {
if ((cacheControlMaxAge == MAX_AGE_NO_INIT) || (cacheControlMaxAge == MAX_AGE_TIME)) {
this.cacheControlMaxAge = cacheControlMaxAge;
} else if (cacheControlMaxAge >= 0) {
// declare the cache control as a constant
// TODO check if this value can be stored as a positive long without changing it
this.cacheControlMaxAge = - cacheControlMaxAge;
} else {
log.warn("OSCache: 'max-age' must be at least a positive integer, defaulting to '60'. ");
this.cacheControlMaxAge = -60;
}
}
/**
* @return the cacheGroupsProvider
* @since 2.4
*/
public ICacheGroupsProvider getCacheGroupsProvider() {
return cacheGroupsProvider;
}
/**
* <b>ICacheGroupsProvider</b> - Class implementing the interface <code>ICacheGroupsProvider</code>.
* A developer can implement a method which provides cache groups based on the request,
* the servlect cache administrator and cache. The parameter has to be not <code>null</code>.
*
* @param cacheGroupsProvider the cacheGroupsProvider to set
* @since 2.4
*/
public void setCacheGroupsProvider(ICacheGroupsProvider cacheGroupsProvider) {
if (cacheGroupsProvider == null) throw new IllegalArgumentException("The ICacheGroupsProvider is null.");
this.cacheGroupsProvider = cacheGroupsProvider;
}
/**
* @return the cacheKeyProvider
* @since 2.4
*/
public ICacheKeyProvider getCacheKeyProvider() {
return cacheKeyProvider;
}
/**
* <b>ICacheKeyProvider</b> - Class implementing the interface <code>ICacheKeyProvider</code>.
* A developer can implement a method which provides cache keys based on the request,
* the servlect cache administrator and cache. The parameter has to be not <code>null</code>.
*
* @param cacheKeyProvider the cacheKeyProvider to set
* @since 2.4
*/
public void setCacheKeyProvider(ICacheKeyProvider cacheKeyProvider) {
if (cacheKeyProvider == null) throw new IllegalArgumentException("The ICacheKeyProvider is null.");
this.cacheKeyProvider = cacheKeyProvider;
}
/**
* Returns PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE.
* @return the cache scope
* @since 2.4
*/
public int getCacheScope() {
return cacheScope;
}
/**
* <b>scope</b> - the default scope to cache content. Acceptable values
* are <code>PageContext.APPLICATION_SCOPE</code> (default) and <code>PageContext.SESSION_SCOPE</code>.
*
* @param cacheScope the cacheScope to set
* @since 2.4
*/
public void setCacheScope(int cacheScope) {
if ((cacheScope != PageContext.APPLICATION_SCOPE) && (cacheScope != PageContext.SESSION_SCOPE))
throw new IllegalArgumentException("Acceptable values for cache scope are PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE");
this.cacheScope = cacheScope;
}
/**
* @return the cron
* @since 2.4
*/
public String getCron() {
return cron;
}
/**
* <b>cron</b> - defines an expression that determines when the page content will expire.
* This allows content to be expired at particular dates and/or times, rather than once
* a cache entry reaches a certain age.
*
* @param cron the cron to set
* @since 2.4
*/
public void setCron(String cron) {
this.cron = cron;
}
/**
* @return the expires header
* @since 2.4
*/
public long getExpires() {
return expires;
}
/**
* <b>expires</b> - defines if the expires header will be sent in the response. Acceptable values are
* <code>EXPIRES_OFF</code> for don't sending the header, even it is set in the filter chain,
* <code>EXPIRES_ON</code> (default) for sending it if it is set in the filter chain and
* <code>EXPIRES_TIME</code> the expires information will be intialized based on the time parameter and creation time of the content.
*
* @param expires the expires to set
* @since 2.4
*/
public void setExpires(long expires) {
if ((expires < EXPIRES_TIME) || (expires > EXPIRES_ON)) throw new IllegalArgumentException("Expires value out of range.");
this.expires = expires;
}
/**
* @return the expiresRefreshPolicy
* @since 2.4
*/
public EntryRefreshPolicy getExpiresRefreshPolicy() {
return expiresRefreshPolicy;
}
/**
* <b>EntryRefreshPolicy</b> - Class implementing the interface <code>EntryRefreshPolicy</code>.
* A developer can implement a class which provides a different custom cache invalidation policy for a specific cache entry.
* If not specified, the default policy is timed entry expiry as specified with the <b>time</b> parameter described above.
*
* @param expiresRefreshPolicy the expiresRefreshPolicy to set
* @since 2.4
*/
public void setExpiresRefreshPolicy(EntryRefreshPolicy expiresRefreshPolicy) {
if (expiresRefreshPolicy == null) throw new IllegalArgumentException("The EntryRefreshPolicy is null.");
this.expiresRefreshPolicy = expiresRefreshPolicy;
}
/**
* @return the fragment
* @since 2.4
*/
public int getFragment() {
return fragment;
}
/**
* <b>fragment</b> - defines if this filter handles fragments of a page. Acceptable values
* are <code>FRAGMENT_AUTODETECT</code> (default) for auto detect, <code>FRAGMENT_NO</code> and <code>FRAGMENT_YES</code>.
*
* @param fragment the fragment to set
* @since 2.4
*/
public void setFragment(int fragment) {
if ((fragment < FRAGMENT_AUTODETECT) || (fragment > FRAGMENT_YES)) throw new IllegalArgumentException("Fragment value out of range.");
this.fragment = fragment;
}
/**
* @return the lastModified
* @since 2.4
*/
public long getLastModified() {
return lastModified;
}
/**
* <b>lastModified</b> - defines if the last modified header will be sent in the response. Acceptable values are
* <code>LAST_MODIFIED_OFF</code> for don't sending the header, even it is set in the filter chain,
* <code>LAST_MODIFIED_ON</code> for sending it if it is set in the filter chain and
* <code>LAST_MODIFIED_INITIAL</code> (default) the last modified information will be set based on the current time and changes are allowed.
*
* @param lastModified the lastModified to set
* @since 2.4
*/
public void setLastModified(long lastModified) {
if ((lastModified < LAST_MODIFIED_INITIAL) || (lastModified > LAST_MODIFIED_ON)) throw new IllegalArgumentException("LastModified value out of range.");
this.lastModified = lastModified;
}
/**
* @return the nocache
* @since 2.4
*/
public int getNocache() {
return nocache;
}
/**
* <b>nocache</b> - defines which objects shouldn't be cached. Acceptable values
* are <code>NOCACHE_OFF</code> (default) and <code>NOCACHE_SESSION_ID_IN_URL</code> if the session id is
* contained in the URL.
*
* @param nocache the nocache to set
* @since 2.4
*/
public void setNocache(int nocache) {
if ((nocache < NOCACHE_OFF) || (nocache > NOCACHE_SESSION_ID_IN_URL)) throw new IllegalArgumentException("Nocache value out of range.");
this.nocache = nocache;
}
/**
* @return the time
* @since 2.4
*/
public int getTime() {
return time;
}
/**
* <b>time</b> - the default time (in seconds) to cache content for. The default
* value is 3600 seconds (one hour). Specifying -1 (indefinite expiry) as the cache
* time will ensure a content does not become stale until it is either explicitly
* flushed or the expires refresh policy causes the entry to expire.
*
* @param time the time to set
* @since 2.4
*/
public void setTime(int time) {
this.time = time;
// check if ExpiresRefreshPolicy has to be reset
if (expiresRefreshPolicy instanceof ExpiresRefreshPolicy) {
((ExpiresRefreshPolicy) expiresRefreshPolicy).setRefreshPeriod(time);
}
}
/**
* @link http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html#getMethod()
* @return the list of http method names for which cacheing should be disabled
* @since 2.4
*/
public List getDisableCacheOnMethods() {
return disableCacheOnMethods;
}
/**
* <b>disableCacheOnMethods</b> - Defines the http method name for which cacheing should be disabled.
* The default value is <code>null</code> for cacheing all requests without regarding the method name.
* @link http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html#getMethod()
* @param disableCacheOnMethods the list of http method names for which cacheing should be disabled
* @since 2.4
*/
public void setDisableCacheOnMethods(List disableCacheOnMethods) {
this.disableCacheOnMethods = disableCacheOnMethods;
}
// TODO: check if getter/setter for oscache-properties-file is possible
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?