Author: sskracic
Date: 2005-01-14 14:25:13 +0100 (Fri, 14 Jan 2005)
New Revision: 178
Modified:
ccm-core/trunk/src/com/arsdigita/bebop/jsp/DefinePage.java
Log:
Amending the DefinePage API to support WestSussex improvements.
Modified: ccm-core/trunk/src/com/arsdigita/bebop/jsp/DefinePage.java
===================================================================
--- ccm-core/trunk/src/com/arsdigita/bebop/jsp/DefinePage.java 2005-01-13 19:49:28 UTC (rev 177)
+++ ccm-core/trunk/src/com/arsdigita/bebop/jsp/DefinePage.java 2005-01-14 13:25:13 UTC (rev 178)
@@ -29,6 +29,9 @@
import java.io.File;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -76,6 +79,11 @@
// maps URL(/packages/foo/www/asdf.jsp) -> {Page, creation date}
private static Map s_pageLocks = new HashMap();
+ // Collection of dirty page URLs (ie/packages/foo/www/asdf.jsp).
+ // Can be set anywhere and is checked here before retreiving page from cache.
+ private static Set s_dirtyPages =
+ Collections.synchronizedSet(new HashSet());
+
/**
* Creates a Bebop Page instance. A page tag is a special case
* because we don't expect it to have a parent tag.
@@ -85,7 +93,7 @@
String cacheKey = DispatcherHelper.getCurrentResourcePath
((HttpServletRequest)pageContext.getRequest());
Object pageLock;
- // First off all we have the global synchronization
+ // First off all we have the global synchronization
// block to get the page's unique sync object.
synchronized (s_pageLocks) {
pageLock = s_pageLocks.get(cacheKey);
@@ -101,11 +109,12 @@
long pageDate = ((Long)pair[1]).longValue();
File jspFile = new File(pageContext.getServletContext()
.getRealPath(cacheKey));
- if (jspFile.lastModified() <= pageDate) {
- // jsp file is not newer than cached page, so we can use
- // the cached page.
+ if (jspFile.lastModified() <= pageDate && !s_dirtyPages.contains(cacheKey)) {
+ // jsp file is not newer than cached page,
+ // and page hasn't been marked as dirty by anyone so we can use the cached page.
+
Page page = (Page)pair[0];
-
+
// We may have to for the page to be locked
// by another thread
while (!page.isLocked()) {
@@ -126,11 +135,19 @@
pageContext.setAttribute(getName(), m_page);
return SKIP_BODY;
}
-
+
+ s_log.debug("rebuilding page - first time requested? "
+ + !s_pageCache.containsKey(cacheKey)
+ + " marked as dirty? "
+ + s_dirtyPages.contains(cacheKey)
+ + " else JSP modified");
+
m_page = buildPage();
s_pageCache.put(cacheKey,
new Object[] {m_page,
new Long(System.currentTimeMillis())});
+ s_dirtyPages.remove(cacheKey);
+
}
} else {
m_page = buildPage();
@@ -139,6 +156,16 @@
return EVAL_BODY_BUFFERED;
}
+ /**
+ * pass in resource URL (eg by using DispatcherHelper.getCurrentResourcePath())
+ * and page will be rebuilt next time it is requested.
+ * @param resourceURL URL for page eg /packages/foo/www/asdf.jsp
+ */
+ public static void setPageAsDirty (String resourceURL) {
+ s_dirtyPages.add(resourceURL);
+ }
+
+
private Page buildPage() throws JspException {
Page page;
@@ -239,10 +266,10 @@
(HttpServletRequest)pageContext.getRequest();
HttpServletResponse resp =
(HttpServletResponse)pageContext.getResponse();
-
+
Document doc;
PageState state;
-
+
try {
doc = new Document ();
state = m_page.process (req, resp);
|