Methods Summary |
---|
public void | destroy()Stop this Context component.
|
public java.lang.String | getCacheKey(javax.servlet.http.HttpServletRequest request)getCacheKey: generate the key to be used to cache this request
// cache mapping associated with the request
CacheMapping mapping = lookupCacheMapping(request);
if (isKeyGeneratorChecked == false && attrKeyGenerator != null) {
try {
keyGenerator = (CacheKeyGenerator)
context.getAttribute(attrKeyGenerator);
} catch (ClassCastException cce){
_logger.log(Level.WARNING, "cache.defaultHelp.illegalKeyGenerator", cce);
}
isKeyGeneratorChecked = true;
}
if (keyGenerator != null) {
String key = keyGenerator.getCacheKey(context, request);
if (key != null)
return key;
}
StringBuffer sb = new StringBuffer(128);
/** XXX: the StringBuffer append is a (uncontended) synchronized method.
* performance hit?
*/
sb.append(request.getServletPath());
// append the key fields
Field[] keys = mapping.getKeyFields();
for (int i = 0; i < keys.length; i++) {
Object value = keys[i].getValue(context, request);
// all defined key field must be present
if (value == null) {
if (_isTraceEnabled) {
_logger.fine("DefaultCacheHelper: cannot find all the required key fields in the request " + request.getServletPath());
}
return null;
}
sb.append(";");
sb.append(KEY_PREFIXES[keys[i].getScope()]);
sb.append(keys[i].getName());
sb.append("=");
sb.append(value);
}
return sb.toString();
|
public int | getTimeout(javax.servlet.http.HttpServletRequest request)get timeout for the cacheable data in this request
// cache mapping associated with the request
CacheMapping mapping = lookupCacheMapping(request);
// get the statically configured value, if any
int result = mapping.getTimeout();
// if the field is not defined, return the configured value
Field field = mapping.getTimeoutField();
if (field != null) {
Object value = field.getValue(context, request);
if (value != null) {
try {
// Integer type timeout object
Integer timeoutAttr = Integer.valueOf(value.toString());
result = timeoutAttr.intValue();
} catch (NumberFormatException cce) { }
}
}
// Note: this could be CacheHelper.TIMEOUT_NOT_SET
return result;
|
public void | init(javax.servlet.ServletContext context, java.util.Map props)initialize this helper
this.context = context;
attrKeyGenerator = (String)props.get(PROP_KEY_GENERATOR_ATTR_NAME);
// web container logger
_logger = LogDomains.getLogger(LogDomains.PWC_LOGGER);
_isTraceEnabled = _logger.isLoggable(Level.FINE);
_rb = _logger.getResourceBundle();
|
public boolean | isCacheable(javax.servlet.http.HttpServletRequest request)isCacheable: is the response to given request cachebale?
boolean result = false;
// cache mapping associated with the request
CacheMapping mapping = lookupCacheMapping(request);
// check if the method is in the allowed methods list
if (mapping.findMethod(request.getMethod())) {
result = true;
ConstraintField fields[] = mapping.getConstraintFields();
// apply all the constraints
for (int i = 0; i < fields.length; i++) {
if (!fields[i].applyConstraints(context, request)) {
result = false;
break;
}
}
}
return result;
|
public boolean | isRefreshNeeded(javax.servlet.http.HttpServletRequest request)isRefreshNeeded: is the response to given request be refreshed?
boolean result = false;
// cache mapping associated with the request
CacheMapping mapping = lookupCacheMapping(request);
Field field = mapping.getRefreshField();
if (field != null) {
Object value = field.getValue(context, request);
// the field's string representation must be "true" or "false"
if (value != null && "true".equals(value.toString())) {
result = true;
}
}
return result;
|
private com.sun.appserv.web.cache.mapping.CacheMapping | lookupCacheMapping(javax.servlet.http.HttpServletRequest request)cache-mapping for this servlet-name or the URLpattern
String name = (String)request.getAttribute(ATTR_CACHING_FILTER_NAME);
return manager.getCacheMapping(name);
|
public void | setCacheManager(CacheManager manager)set the CacheManager for this application
this.manager = manager;
|