📄 cmsflexcacheentry.java
字号:
if (!m_completed) return;
if (m_redirectTarget != null) {
res.setOnlyBuffering(false);
// Redirect the response, no further output required
res.sendRedirect(m_redirectTarget);
} else {
// Process cached headers first
CmsFlexResponse.processHeaders(m_headers, res);
// Check if this cache entry is a "leaf" (i.e. no further includes)
boolean hasNoSubElements = ((m_elements != null) && (m_elements.size() == 1));
// Write output to stream and process all included elements
java.util.Iterator i = m_elements.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof String) {
// Handle cached parameters
java.util.Map map = (java.util.Map)i.next();
java.util.Map oldMap = null;
if (map.size() > 0) {
oldMap = req.getParameterMap();
req.addParameterMap(map);
}
// Do the include call
req.getRequestDispatcher((String)o).include(req, res);
// Reset parameters if neccessary
if (oldMap != null) req.setParameterMap(oldMap);
} else {
try {
res.writeToOutputStream((byte[])o, hasNoSubElements);
} catch (java.io.IOException e) {
String err = this.getClass().getName() + ": Could not write to response OutputStream. ";
if (DEBUG > 0) System.err.println(err);
throw new com.opencms.core.CmsException(err + "\n" + e, e);
}
}
}
}
}
/**
* Returns the timeout - value of this cache entry,
* this is set to the time when the entry becomes invalid.
*
* @return the timeout value for this resource
*/
public long getTimeout() {
return m_timeout;
}
/**
* Sets a timeout value to this cache entry,
* which indicates the time this entry becomes invalid.<p>
*
* The timeout parameter represents the minute - intervall in which the cache entry
* is to be cleared.
* The intervall always starts at 0.00h.
* A value of 60 would indicate that this entry will reach it's timeout at the beginning of the next
* full hour, a timeout of 20 would indicate that the entry is invalidated at x.00, x.20 and x.40 of every hour etc.<p>
*
* @param timeout the timeout value to be set
*/
public synchronized void setTimeout(long timeout) {
if (timeout < 0 || ! m_completed) return;
long now = System.currentTimeMillis();
long daytime = now % 86400000;
m_timeout = now - (daytime % timeout) + timeout;
if (DEBUG > 2) System.err.println("FlexCacheEntry: New entry timeout=" + m_timeout + " now=" + now + " remaining=" + (m_timeout - now) );
}
/**
* Completes this cache entry.<p>
*
* A completed cache entry is made "unmodifiable",
* so that no further data can be added and existing data can not be changed.
* This is to prevend the (unlikley) case that some user-written class
* tries to make changes to a cache entry.<p>
*/
public void complete() {
m_completed = true;
// Prevent changing of the cached lists
if (m_headers != null) {
m_headers = java.util.Collections.unmodifiableMap(m_headers);
}
if (m_elements != null) {
m_elements = java.util.Collections.unmodifiableList(m_elements);
}
if (DEBUG > 1) System.err.println("CmsFlexCacheEntry: New entry completed:\n" + this.toString());
}
/**
* @see java.lang.Object#toString()
*
* @return a basic String representation of this CmsFlexCache entry
*/
public String toString() {
String str = null;
if (m_redirectTarget == null) {
str = "CmsFlexCacheEntry [" + m_elements.size() + " Elements/" + this.getLruCacheCosts() + " bytes]\n";
java.util.Iterator i = m_elements.iterator();
int count = 0;
while (i.hasNext()) {
count++;
Object o = i.next();
if (o instanceof String) {
str += "" + count + " - <cms:include target=" + o + ">\n";
} else {
str += "" + count + " - <![CDATA[" + new String((byte[])o) + "]]>\n";
}
}
} else {
str = "CmsFlexCacheEntry [Redirect to target=" + m_redirectTarget + "]";
}
return str;
}
/**
* Stores a backward reference to the map and key where this cache entry is stored.
*
* This is required for the FlexCache.<p>
*
* @param theVariationKey the variation key
* @param theVariationMap the variation map
*/
public void setVariationData( String theVariationKey, Map theVariationMap ) {
this.m_VariationKey = theVariationKey;
this.m_VariationMap = theVariationMap;
}
// implementation of the com.opencms.flex.util.I_CmsFlexLruCacheObject interface methods
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#setNextLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject)
*/
public void setNextLruObject( I_CmsFlexLruCacheObject theNextEntry ) {
this.m_Next = theNextEntry;
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#getNextLruObject()
*/
public I_CmsFlexLruCacheObject getNextLruObject() {
return this.m_Next;
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#setPreviousLruObject(com.opencms.flex.util.I_CmsFlexLruCacheObject)
*/
public void setPreviousLruObject( I_CmsFlexLruCacheObject thePreviousEntry ) {
this.m_Previous = thePreviousEntry;
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#getPreviousLruObject()
*/
public I_CmsFlexLruCacheObject getPreviousLruObject() {
return this.m_Previous;
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#addToLruCache()
*/
public void addToLruCache() {
// do nothing here...
if (DEBUG>0) System.out.println( "Added cache entry with ID: " + this.ID + " to the LRU cache" );
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#removeFromLruCache()
*/
public void removeFromLruCache() {
if (m_VariationMap!=null && this.m_VariationKey!=null) {
this.m_VariationMap.remove( this.m_VariationKey );
if (DEBUG>0) System.err.println( "Removed cache entry with ID: " + this.ID + " from the LRU cache" );
}
}
/**
* @see com.opencms.flex.util.I_CmsFlexLruCacheObject#getLruCacheCosts()
*/
public int getLruCacheCosts() {
return m_byteSize;
}
// methods to clean-up/finalize the object instance
/**
* Finalize this instance.<p>
*
* @see java.lang.Object#finalize()
*/
protected void finalize() throws java.lang.Throwable {
if (DEBUG>0) System.err.println( "Finalizing cache entry with ID: " + this.ID );
this.clear();
this.m_elements = null;
this.m_headers = null;
this.m_VariationKey = null;
this.m_VariationMap = null;
this.setNextLruObject( null );
this.setPreviousLruObject( null );
this.m_byteSize = 0;
super.finalize();
}
/**
* Clears the elements and headers HashMaps.<p>
*/
private void clear() {
m_elements.clear();
m_headers.clear();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -