📄 cmsflexcacheentry.java
字号:
*/
public I_CmsLruCacheObject getNextLruObject() {
return m_next;
}
/**
* @see org.opencms.cache.I_CmsLruCacheObject#getPreviousLruObject()
*/
public I_CmsLruCacheObject getPreviousLruObject() {
return m_previous;
}
/**
* @see org.opencms.cache.I_CmsLruCacheObject#getValue()
*/
public Object getValue() {
return m_elements;
}
/**
* @see org.opencms.cache.I_CmsLruCacheObject#removeFromLruCache()
*/
public void removeFromLruCache() {
if ((m_variationMap != null) && (m_variationKey != null)) {
m_variationMap.remove(m_variationKey);
}
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_FLEXCACHEENTRY_REMOVED_ENTRY_FOR_VARIATION_1,
m_variationKey));
}
clear();
}
/**
* Processing method for this cached entry.<p>
*
* If this method is called, it delivers the contents of
* the cached entry to the given request / response.
* This includes calls to all included resources.<p>
*
* @param req the request from the client
* @param res the server response
* @throws CmsFlexCacheException is thrown when problems writing to the response output-stream occur
* @throws ServletException might be thrown from call to RequestDispatcher.include()
* @throws IOException might be thrown from call to RequestDispatcher.include() or from Response.sendRedirect()
*/
public void service(CmsFlexRequest req, CmsFlexResponse res)
throws CmsFlexCacheException, ServletException, IOException {
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
for (int i = 0; i < m_elements.size(); i++) {
Object o = m_elements.get(i);
if (o instanceof String) {
// handle cached parameters
i++;
Map map = (Map)m_elements.get(i);
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 (IOException e) {
CmsMessageContainer message = Messages.get().container(
Messages.LOG_FLEXCACHEKEY_NOT_FOUND_1,
getClass().getName());
if (LOG.isDebugEnabled()) {
LOG.debug(message.key());
}
throw new CmsFlexCacheException(message, e);
}
}
}
}
}
/**
* Sets the expiration date of this Flex cache entry exactly to the
* given time.<p>
*
* @param dateExpires the time to expire this cache entry
*/
public synchronized void setDateExpires(long dateExpires) {
m_dateExpires = dateExpires;
if (LOG.isDebugEnabled()) {
long now = System.currentTimeMillis();
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_FLEXCACHEENTRY_SET_EXPIRATION_DATE_3,
new Long(m_dateExpires),
new Long(now),
new Long(m_dateExpires - now)));
}
}
/**
* Sets an expiration date for this cache entry to the next timeout,
* 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 expiration date 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 void setDateExpiresToNextTimeout(long timeout) {
if (timeout < 0 || !m_completed) {
return;
}
long now = System.currentTimeMillis();
long daytime = now % 86400000;
long timeoutMinutes = timeout * 60000;
setDateExpires(now - (daytime % timeoutMinutes) + timeoutMinutes);
}
/**
* Sets the "last modified" date for this Flex cache entry with the given value.<p>
*
* @param dateLastModified the value to set for the "last modified" date
*/
public void setDateLastModified(long dateLastModified) {
m_dateLastModified = dateLastModified;
}
/**
* Sets the "last modified" date for this Flex cache entry by using the last passed timeout value.<p>
*
* If a cache entry uses the timeout feature, it becomes invalid every time the timeout interval
* passes. Thus the "last modified" date is the time the last timeout passed.<p>
*
* @param timeout the timeout value to use to calculate the date last modified
*/
public void setDateLastModifiedToPreviousTimeout(long timeout) {
long now = System.currentTimeMillis();
long daytime = now % 86400000;
long timeoutMinutes = timeout * 60000;
setDateLastModified(now - (daytime % timeoutMinutes));
}
/**
* @see org.opencms.cache.I_CmsLruCacheObject#setNextLruObject(org.opencms.cache.I_CmsLruCacheObject)
*/
public void setNextLruObject(I_CmsLruCacheObject theNextEntry) {
m_next = theNextEntry;
}
/**
* @see org.opencms.cache.I_CmsLruCacheObject#setPreviousLruObject(org.opencms.cache.I_CmsLruCacheObject)
*/
public void setPreviousLruObject(I_CmsLruCacheObject thePreviousEntry) {
m_previous = thePreviousEntry;
}
/**
* Set a redirect target for this cache entry.<p>
*
* <b>Important:</b>
* When a redirect target is set, all saved data is thrown away,
* and new data will not be saved in the cache entry.
* This is so since with a redirect nothing will be displayed
* in the browser anyway, so there is no point in saving the data.<p>
*
* @param target The redirect target (must be a valid URL).
*/
public void setRedirect(String target) {
if (m_completed) {
return;
}
m_redirectTarget = target;
m_byteSize = 512 + CmsMemoryMonitor.getMemorySize(target);
// If we have a redirect we don't need any other output or headers
m_elements = null;
m_headers = null;
}
/**
* 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) {
m_variationKey = theVariationKey;
m_variationMap = theVariationMap;
}
/**
* @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/" + getLruCacheCosts() + " bytes]\n";
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 if (o instanceof byte[]) {
str += "" + count + " - <![CDATA[" + new String((byte[])o) + "]]>\n";
} else {
str += "<!--[" + o.toString() + "]-->";
}
}
} else {
str = "CmsFlexCacheEntry [Redirect to target=" + m_redirectTarget + "]";
}
return str;
}
/**
* Finalize this instance.<p>
*
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
try {
clear();
} catch (Throwable t) {
// ignore
}
super.finalize();
}
/**
* Clears the elements and headers HashMaps.<p>
*/
private void clear() {
// the maps have been made immutable, so we just can set them to null
m_elements = null;
m_headers = null;
// also remove references to other objects
m_variationKey = null;
m_variationMap = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -