logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

roller/src/org/roller/presentation/caching CommonsPageCache.java,1.13,1.14: msg#00161

Subject: roller/src/org/roller/presentation/caching CommonsPageCache.java,1.13,1.14
Update of /cvsroot/roller/roller/src/org/roller/presentation/caching
In directory sc8-pr-cvs1:/tmp/cvs-serv19889/src/org/roller/presentation/caching

Modified Files:
        CommonsPageCache.java 
Log Message:
Fix caching: a seperate list of cached pages is maintained for each logged in 
user (much like the OSCache filter does it).

Index: CommonsPageCache.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/presentation/caching/CommonsPageCache.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** CommonsPageCache.java       18 Mar 2003 03:11:56 -0000      1.13
--- CommonsPageCache.java       18 Mar 2003 16:27:38 -0000      1.14
***************
*** 39,42 ****
--- 39,46 ----
   * cache item's for that user (i.e. when the user updates their site) and not
   * have to clear ALL pages in the cache.
+  * 
+  * A "seperate" cache is maintained for each logged in user (this allows the
+  * "edit" links to be displayed).
+  * 
   * @author llavandowska
   */
***************
*** 63,81 ****
      private int  mTime = 60 * 60 * 1000;
  
- 
-     public void flushCache(HttpServletRequest req)
-     {
-         getCache().clear();
-     }
- 
-     public void removeFromCache(HttpServletRequest req,UserData user)
-     {
-         getCache().clearGroup( user.getUserName() );
-     }
- 
-     public void destroy()
-     {
-     }
- 
      /**
       * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
--- 67,70 ----
***************
*** 91,98 ****
          HttpServletRequest request = (HttpServletRequest) req;
          HttpServletResponse response = (HttpServletResponse) resp;
! 
          RollerRequest rreq = RollerRequest.getRollerRequest(request);
!         String username = "unknown";
!         boolean loggedIn = false;
          if ( rreq.getUser() == null )
          {
--- 80,86 ----
          HttpServletRequest request = (HttpServletRequest) req;
          HttpServletResponse response = (HttpServletResponse) resp;
!               
          RollerRequest rreq = RollerRequest.getRollerRequest(request);
!         String reqUser = "unknown";
          if ( rreq.getUser() == null )
          {
***************
*** 101,111 ****
          else
          {
!             username = rreq.getUser().getUserName();
!             
!             // does the current page belong to the person logged in?
!             if (username.equals(request.getUserPrincipal()))
!             {
!                 loggedIn = true;
!             }
          }
          String catname =
--- 89,93 ----
          else
          {
!             reqUser = rreq.getUser().getUserName();
          }
          String catname =
***************
*** 118,122 ****
          {
              updateTime = rreq.getRoller().getWeblogManager()
!                             .getWeblogLastPublishTime( username, catname);
          }
          catch (RollerException e1)
--- 100,104 ----
          {
              updateTime = rreq.getRoller().getWeblogManager()
!                             .getWeblogLastPublishTime( reqUser, catname);
          }
          catch (RollerException e1)
***************
*** 146,160 ****
              requestedURI = requestedURI + "?" + request.getQueryString();
          }
  
          // see if it is already cached
          byte[] pageVal = null;
!         if (!loggedIn)
          {
!             Object cacheVal = cache.retrieve(requestedURI);
!             if (cacheVal != null && cacheVal instanceof byte[])
!             {
!                 pageVal = (byte[])cacheVal;
!                 mLogger.debug("CommonsPageCache: content is cached.");
!             }
          }
  
--- 128,149 ----
              requestedURI = requestedURI + "?" + request.getQueryString();
          }
+         requestedURI = requestedURI.toLowerCase();
+ 
+               // Add authenticated user name to cache key
+               java.security.Principal prince =
+                       ((HttpServletRequest)request).getUserPrincipal();
+               String authUser = (prince==null) ? "anonymous" : 
prince.getName();
+ 
+               // This cache key ensures that each logged in user has his own
+               // cache of pages, but that anonymous users share one cache
+         String key = authUser + ":" + requestedURI;
  
          // see if it is already cached
          byte[] pageVal = null;
!         Object cacheVal = cache.retrieve(key);
!         if (cacheVal != null && cacheVal instanceof byte[])
          {
!             pageVal = (byte[])cacheVal;
!             mLogger.debug("CommonsPageCache: got cache for " + key);
          }
  
***************
*** 172,192 ****
          }
  
!         // get the real underlying OutputStream
                ByteArrayOutputStream baStream = newOut.getByteArrayStream();
  
          // The content wasn't cached before, no exceptions
!               // were noted during execution of the filter chain,
!         // and this is not our user's page.
!         if (!loggedIn && pageVal == null && baStream.size() > 0 &&
                        request.getAttribute("DisplayException") == null)
          {
              pageVal = baStream.toByteArray();
!             cache.store(requestedURI,
                      pageVal,
                      new Long(System.currentTimeMillis() + mTime),
                      null,
!                     username); // this allows us to clear the
!                               // whole bunch for this user at once.
!                       mLogger.debug("CommonsPageCache: caching content.");
          }
                else if (pageVal != null)
--- 161,180 ----
          }
  
!         // get the wrapped OutputStream
                ByteArrayOutputStream baStream = newOut.getByteArrayStream();
  
          // The content wasn't cached before, no exceptions
!               // were noted during execution of the filter chain.
!         if (pageVal == null && baStream.size() > 0 &&
                        request.getAttribute("DisplayException") == null)
          {
              pageVal = baStream.toByteArray();
!             cache.store(key,
                      pageVal,
                      new Long(System.currentTimeMillis() + mTime),
                      null,
!                     reqUser); // this allows us to clear the
!                                                         // whole bunch for 
this user at once.
!                       mLogger.debug("CommonsPageCache: caching content for " 
+ key);
          }
                else if (pageVal != null)
***************
*** 201,204 ****
--- 189,207 ----
                myWrappedResp.getOutputStream().close(); 
      }
+ 
+ 
+       public void flushCache(HttpServletRequest req)
+       {
+               getCache().clear();
+       }
+ 
+       public void removeFromCache(HttpServletRequest req,UserData user)
+       {
+               getCache().clearGroup( user.getUserName() );
+       }
+ 
+       public void destroy()
+       {
+       }
  
      /**




-------------------------------------------------------
This SF.net email is sponsored by: Does your code think in ink? 
You could win a Tablet PC. Get a free Tablet PC hat just for playing. 
What are you waiting for?
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en


<Prev in Thread] Current Thread [Next in Thread>