You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by mo...@apache.org on 2001/11/16 14:54:53 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/caching DeltaTimeCacheValidity.java

morrijr     01/11/16 05:54:53

  Added:       src/org/apache/cocoon/caching DeltaTimeCacheValidity.java
  Log:
  Keeps the result of an XSP page in cache for a specified amount of time - Michael Homeijer (mailto:M.Homeijer@devote.nl)
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/org/apache/cocoon/caching/DeltaTimeCacheValidity.java
  
  Index: DeltaTimeCacheValidity.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.caching;
  
  import java.util.Date;
  import java.lang.Math;
  
  /**
   * A validation object that remains valid for a specified amount of time (minutes).
   *
   * @author Michael Homeijer
   */
  
  public final class DeltaTimeCacheValidity implements CacheValidity
  {
  
      private long cachedDateTime;  // Holds the store-time in miliseconds
      private long timeInCache;     // maximum time allowed in cache in minutes
  
      public DeltaTimeCacheValidity(long timeInCache)
      {
  	this.cachedDateTime = new Date().getTime();
  	this.timeInCache = timeInCache * 60000;
      }
  
      public boolean isValid(CacheValidity validity)
      {
          if (validity instanceof DeltaTimeCacheValidity)
          {
              return Math.abs((((DeltaTimeCacheValidity)validity).getCachedDateTime() - this.cachedDateTime)) < this.timeInCache;
          }
          return false;
      }
  
      public long getCachedDateTime()
      {
          return this.cachedDateTime;
      }
  
      public String toString()
      {
          return "DeltaTimeCacheValidity: " + this.cachedDateTime + "(+" + this.timeInCache + "min)";
      }
  
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org