if (valid == SourceValidity.UNKNOWN) {
// get reader validity and compare
if (isCacheableProcessingComponent) {
readerValidity = ((CacheableProcessingComponent) super.reader).getValidity();
} else {
CacheValidity cv = ((Cacheable) super.reader).generateValidity();
if (cv != null) {
readerValidity = CacheValidityToSourceValidity.createValidity(cv);
}
}
if (readerValidity != null) {
valid = cachedValidity.isValid(readerValidity);
if (valid == SourceValidity.UNKNOWN) {
readerValidity = null;
} else {
isValid = (valid == SourceValidity.VALID);
}
}
} else {
isValid = (valid == SourceValidity.VALID);
}
if (isValid) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("processReader: using valid cached content for '" +
environment.getURI() + "'.");
}
byte[] response = cachedObject.getResponse();
if (response.length > 0) {
usedCache = true;
if (cachedObject.getContentType() != null) {
environment.setContentType(cachedObject.getContentType());
} else {
setMimeTypeForReader(environment);
}
outputStream = environment.getOutputStream(0);
environment.setContentLength(response.length);
outputStream.write(response);
}
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("processReader: cached content is invalid for '" +
environment.getURI() + "'.");
}
// remove invalid cached object
this.cache.remove(pcKey);
}
}
} else {
// check if something is being generated right now
if (!waitForLock(environment, pcKey)) {
finished = false;
continue;
}
}
}
}
if (!usedCache) {
// make sure lock will be released
try {
if (pcKey != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("processReader: caching content for further requests of '" +
environment.getURI() + "'.");
}
generateLock(environment, pcKey);
if (readerValidity == null) {
if (isCacheableProcessingComponent) {
readerValidity = ((CacheableProcessingComponent)super.reader).getValidity();
} else {
CacheValidity cv = ((Cacheable)super.reader).generateValidity();
if ( cv != null ) {
readerValidity = CacheValidityToSourceValidity.createValidity( cv );
}
}
}