You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gr...@locus.apache.org on 2000/11/01 21:12:48 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/cache NoCache.java CocoonCache.java Cache.java

greenrd     00/11/01 12:12:47

  Modified:    src/org/apache/cocoon cocoon.properties Engine.java
               src/org/apache/cocoon/store Store.java MemoryStore.java
               src/org/apache/cocoon/cache NoCache.java CocoonCache.java
                        Cache.java
  Log:
  Cocoon now optionally sets Last-Modified HTTP header
  
  Revision  Changes    Path
  1.41      +2 -1      xml-cocoon/src/org/apache/cocoon/cocoon.properties
  
  Index: cocoon.properties
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cocoon.properties,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- cocoon.properties	2000/10/02 20:44:43	1.40
  +++ cocoon.properties	2000/11/01 20:12:15	1.41
  @@ -297,7 +297,8 @@
   # disable page caching
   #cache = org.apache.cocoon.cache.NoCache
   
  -
  +#Change this to false to disable Last-Modified headers
  +lastmodified = true
   
   
   ##########################################
  
  
  
  1.36      +14 -9     xml-cocoon/src/org/apache/cocoon/Engine.java
  
  Index: Engine.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Engine.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Engine.java	2000/10/15 22:43:13	1.35
  +++ Engine.java	2000/11/01 20:12:17	1.36
  @@ -1,4 +1,4 @@
  -/*-- $Id: Engine.java,v 1.35 2000/10/15 22:43:13 greenrd Exp $ --
  +/*-- $Id: Engine.java,v 1.36 2000/11/01 20:12:17 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -75,13 +75,13 @@
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    * @author <a href="mailto:greenrd@hotmail.com">Robin Green</a>
  - * @version $Revision: 1.35 $ $Date: 2000/10/15 22:43:13 $
  + * @version $Revision: 1.36 $ $Date: 2000/11/01 20:12:17 $
    */
   
   public class Engine implements Defaults {
   
       private Block blocker = new Block();
  -    private boolean VERBOSE, PROFILE;
  +    private boolean VERBOSE, PROFILE, LASTMODIFIED;
   
       private static Hashtable engineInstances = new Hashtable(2, 0.90f);
   
  @@ -186,6 +186,7 @@
           manager.setRole("browsers", browsers);
   
           VERBOSE = configurations.get ("verbosity", "false").equals ("true");
  +        LASTMODIFIED = configurations.get ("lastmodified", "true").equals ("true");
   
           // If enabled, create the profiler and register it
           PROFILE = configurations.get ("profiler.enabled", "false").equals ("true");
  @@ -303,7 +304,7 @@
                   // a valid instance (no changeable points have changed)
                   page = cache.getPage(request);
   
  -                // if the page isn't in cache block any furhter access to this page
  +                // if the page isn't in cache block any further access to this page
                   // until it get's put into cache
                   if ( page == null ) {
   
  @@ -318,12 +319,11 @@
                   }
               }
   
  -            // the page was not found in the cache or the cache was
  -            // disabled, we need to process it
  -
  -
               if (page == null) {
   
  +                // the page was not found in the cache or the cache was
  +                // disabled, we need to process it
  +
                   if (LOG) logger.log(this, "Creating page", Logger.DEBUG);
   
                   // continue until the page is done.
  @@ -394,6 +394,9 @@
                               page.setContentType(formatter.getMIMEType());
                           }
   
  +                        // cache the created page.
  +                        cache.setPage(page, request);
  +
                           // page is done without memory errors so exit the loop
                           break;
                       } catch (OutOfMemoryError e) {
  @@ -421,6 +424,11 @@
                   // set the response content type
                   response.setContentType(page.getContentType());
   
  +                // set the Last-Modified header if this option is enabled in cocoon.properties
  +                if (LASTMODIFIED) {
  +                   response.setDateHeader ("Last-Modified", cache.getLastModified (request));
  +                }
  +
                   // get the output writer
                   PrintWriter out = response.getWriter();
   
  @@ -446,9 +454,6 @@
   
               if (LOG) logger.log(this, "response sent to client", Logger.WARNING);
               if (PROFILE) profiler.finishEvent (requestMarker, WHOLE_REQUEST);
  -
  -            // cache the created page.
  -            cache.setPage(page, request);
   
           } finally {
               // if there is a lock make sure it is released,
  
  
  
  1.7       +8 -2      xml-cocoon/src/org/apache/cocoon/store/Store.java
  
  Index: Store.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/store/Store.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Store.java	2000/02/14 00:59:19	1.6
  +++ Store.java	2000/11/01 20:12:27	1.7
  @@ -1,4 +1,4 @@
  -/*-- $Id: Store.java,v 1.6 2000/02/14 00:59:19 stefano Exp $ --
  +/*-- $Id: Store.java,v 1.7 2000/11/01 20:12:27 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -59,7 +59,7 @@
    * implement.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.6 $ $Date: 2000/02/14 00:59:19 $
  + * @version $Revision: 1.7 $ $Date: 2000/11/01 20:12:27 $
    */
   
   public interface Store {
  @@ -68,6 +68,12 @@
        * Get the object associated to the given unique key.
        */
       Object get(Object key);
  +
  +    /**
  +     * Get the time the object was added.
  +     * @throws NullPointerException if the object is not in the store.
  +     */
  +    long getTime(Object key);
   
       /**
        * Store the given object in a persistent state. It is up to the
  
  
  
  1.13      +13 -4     xml-cocoon/src/org/apache/cocoon/store/MemoryStore.java
  
  Index: MemoryStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/store/MemoryStore.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MemoryStore.java	2000/05/16 21:11:51	1.12
  +++ MemoryStore.java	2000/11/01 20:12:28	1.13
  @@ -1,4 +1,4 @@
  -/*-- $Id: MemoryStore.java,v 1.12 2000/05/16 21:11:51 stefano Exp $ --
  +/*-- $Id: MemoryStore.java,v 1.13 2000/11/01 20:12:28 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -67,7 +67,7 @@
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
    * @author <a href="mailto:michel.lehon@outwares.com">Michel Lehon</a>
  - * @version $Revision: 1.12 $ $Date: 2000/05/16 21:11:51 $
  + * @version $Revision: 1.13 $ $Date: 2000/11/01 20:12:28 $
    */
   
   public class MemoryStore implements Store, Status, Configurable, Runnable {
  @@ -103,16 +103,17 @@
   
       class Container {
           public Object object;
  -        public long time = 0;
  +        public long time = 0, timeAdded = 0;
           public int count = 0;
   
           public Container(Object object) {
               this.object = object;
  +            timeAdded = System.currentTimeMillis ();
           }
       }
   
       /**
  -     * Initialize the MemoryStore. 
  +     * Initialize the MemoryStore.
        * A few options can be used :
        * <UL>
        *  <LI>freememory = How much memory to keep free for normal jvm operation. (Default: 1 Mb)</LI>
  @@ -209,6 +210,14 @@
           } else {
               return null;
           }
  +    }
  +
  +    /**
  +     * Gets the time this object was added.
  +     * @throws NullPointerException if the object is not in the store.
  +     */
  +    public long getTime(Object key) throws NullPointerException {
  +      return ((Container) hashtable.get (key)).timeAdded;
       }
   
       /**
  
  
  
  1.6       +9 -2      xml-cocoon/src/org/apache/cocoon/cache/NoCache.java
  
  Index: NoCache.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/NoCache.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NoCache.java	2000/02/14 00:59:18	1.5
  +++ NoCache.java	2000/11/01 20:12:38	1.6
  @@ -1,4 +1,4 @@
  -/*-- $Id: NoCache.java,v 1.5 2000/02/14 00:59:18 stefano Exp $ --
  +/*-- $Id: NoCache.java,v 1.6 2000/11/01 20:12:38 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -57,7 +57,7 @@
    * A caching implementation that doesn't cache anything :).
    *
    * @author <a href="stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.5 $Date: 2000/02/14 00:59:18 $
  + * @version $Revision: 1.6 $Date: 2000/11/01 20:12:38 $
    */
   public class NoCache extends AbstractActor implements Cache, Status {
   
  @@ -71,6 +71,13 @@
   
       public void flush() {
       	Runtime.getRuntime().gc();
  +    }
  +
  +    /**
  +     * Just returns the current time.
  +     */
  +    public long getLastModified(HttpServletRequest request) {
  +      return System.currentTimeMillis ();
       }
   
       public String getStatus() {
  
  
  
  1.7       +17 -3     xml-cocoon/src/org/apache/cocoon/cache/CocoonCache.java
  
  Index: CocoonCache.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/CocoonCache.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CocoonCache.java	2000/02/14 00:59:18	1.6
  +++ CocoonCache.java	2000/11/01 20:12:40	1.7
  @@ -1,4 +1,4 @@
  -/*-- $Id: CocoonCache.java,v 1.6 2000/02/14 00:59:18 stefano Exp $ --
  +/*-- $Id: CocoonCache.java,v 1.7 2000/11/01 20:12:40 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -62,7 +62,7 @@
    * statically and dynamically generated.
    *
    * @author <a href="stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.6 $Date: 2000/02/14 00:59:18 $
  + * @version $Revision: 1.7 $Date: 2000/11/01 20:12:40 $
    */
   public class CocoonCache implements Cache, Status {
   
  @@ -99,6 +99,20 @@
       }
   
       /**
  +     * Get the time that this request was added to the cache.
  +     * If the request is no longer in the cache (maybe it was
  +     * cleared due to low memory), just returns the current time.
  +     */
  +    public long getLastModified(HttpServletRequest request) {
  +      try {
  +        return store.getTime (request);
  +      }
  +      catch (NullPointerException ex) {
  +        return System.currentTimeMillis ();
  +      }
  +    }
  +
  +    /**
        * This method inserts the page in cache and associates it
        * with the given request.
        */
  @@ -120,4 +134,4 @@
       public String getStatus() {
           return "Cocoon Dynamic Cache System";
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.6       +9 -2      xml-cocoon/src/org/apache/cocoon/cache/Cache.java
  
  Index: Cache.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/Cache.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Cache.java	2000/02/14 00:59:18	1.5
  +++ Cache.java	2000/11/01 20:12:40	1.6
  @@ -1,4 +1,4 @@
  -/*-- $Id: Cache.java,v 1.5 2000/02/14 00:59:18 stefano Exp $ --
  +/*-- $Id: Cache.java,v 1.6 2000/11/01 20:12:40 greenrd Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -57,7 +57,7 @@
    * The interface that all caching implementations must adhere to.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.5 $Date: 2000/02/14 00:59:18 $
  + * @version $Revision: 1.6 $Date: 2000/11/01 20:12:40 $
    */
   
   public interface Cache extends Actor {
  @@ -73,6 +73,13 @@
        * object for indexing.
        */
       public void setPage(Page page, HttpServletRequest request);
  +
  +    /**
  +     * Get the time that this request was added to the cache.
  +     * If the request is no longer in the cache (maybe it was
  +     * cleared due to low memory), just returns the current time.
  +     */
  +    public long getLastModified(HttpServletRequest request);
   
       /**
        * Flushes the cache and forces an additional cache cleanup. This is