You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by xa...@apache.org on 2009/01/24 12:49:04 UTC

svn commit: r737336 - in /ant/ivy/core/trunk: doc/settings/caches/ttl.html src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java

Author: xavier
Date: Sat Jan 24 11:49:04 2009
New Revision: 737336

URL: http://svn.apache.org/viewvc?rev=737336&view=rev
Log:
add 'eternal' option to ttl and review how expiration is handled so that ttl is evaluated when checking the cache and not when storing the resolved revision, which makes possible to temporarily set the ttl to 'eternal' when resolving dependencies offline for instance (related to IVY-879)

Modified:
    ant/ivy/core/trunk/doc/settings/caches/ttl.html
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java

Modified: ant/ivy/core/trunk/doc/settings/caches/ttl.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/settings/caches/ttl.html?rev=737336&r1=737335&r2=737336&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/settings/caches/ttl.html (original)
+++ ant/ivy/core/trunk/doc/settings/caches/ttl.html Sat Jan 24 11:49:04 2009
@@ -40,6 +40,8 @@
 </code>
 Where 'd' stands for days, 'h' for hours, 'm' for minutes, 's' for seconds and 'ms' for milliseconds. Any part of the specification can be omitted, so '12d', '2h 5m' and '1d 5ms' are all valid.
 
+The TTL duration can also be set to 'eternal', in which case once resolved the revision is always use, except when resolving in refresh mode. 
+
 Using a 0ms TTL disable resolved revision caching for the given rule.
 
 <h1>Attributes</h1>
@@ -58,7 +60,7 @@
         <td>No, defaults to *</td></tr>
     <tr><td>matcher</td><td>the <a href="../../concept.html#matcher">matcher</a> to use to match the modules to which the resolver should be applied</td>
         <td>No, defaults to exact</td></tr>
-    <tr><td>duration</td><td>the TTL to apply</td>
+    <tr><td>duration</td><td>the TTL to apply (see above for format)</td>
         <td>Yes</td></tr>
 </tbody>
 </table>

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=737336&r1=737335&r2=737336&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java Sat Jan 24 11:49:04 2009
@@ -257,6 +257,9 @@
         if (duration == null) {
             return 0;
         }
+        if ("eternal".equals(duration)) {
+            return Long.MAX_VALUE;
+        }
         java.util.regex.Matcher m = DURATION_PATTERN.matcher(duration);
         if (m.matches()) {
             //CheckStyle:MagicNumber| OFF
@@ -274,7 +277,8 @@
             + millis;
         } else {
             throw new IllegalArgumentException("invalid duration '" 
-                + duration + "': it must match " + DURATION_PATTERN.pattern());
+                + duration + "': it must match " + DURATION_PATTERN.pattern()
+                + " or 'eternal'");
         }
     }
 
@@ -664,18 +668,23 @@
                 return null;
             }
             PropertiesFile cachedResolvedRevision = getCachedDataFile(mrid);
-            String expiration = cachedResolvedRevision.getProperty("expiration.time");
-            if (expiration == null) {
-                Message.verbose("no cached resolved revision for " + mrid);
-                return null;
-            } 
-            if (System.currentTimeMillis() > Long.parseLong(expiration)) {
-                Message.verbose("cached resolved revision expired for " + mrid);
-                return null;
-            }
             resolvedRevision = cachedResolvedRevision.getProperty("resolved.revision");
             if (resolvedRevision == null) {
-                Message.verbose("no cached resolved revision value for " + mrid);
+                Message.verbose(getName() + ": no cached resolved revision for " + mrid);
+                return null;
+            }
+            
+            String resolvedTime = cachedResolvedRevision.getProperty("resolved.time");
+            if (resolvedTime == null) {
+                Message.verbose(getName() 
+                    + ": inconsistent or old cache: no cached resolved time for " + mrid);
+                saveResolvedRevision(mrid, resolvedRevision);
+                return resolvedRevision;
+            } 
+            long expiration = Long.parseLong(resolvedTime) + getTTL(mrid);
+            if (expiration > 0 // negative expiration means that Long.MAX_VALUE has been exceeded
+                    && System.currentTimeMillis() > expiration) {
+                Message.verbose(getName() + ": cached resolved revision expired for " + mrid);
                 return null;
             }
             return resolvedRevision;
@@ -691,7 +700,8 @@
         }
         try {
             PropertiesFile cachedResolvedRevision = getCachedDataFile(mrid);
-            cachedResolvedRevision.setProperty("expiration.time", getExpiration(mrid));
+            cachedResolvedRevision.setProperty(
+                "resolved.time", String.valueOf(System.currentTimeMillis()));
             cachedResolvedRevision.setProperty("resolved.revision", revision);
             cachedResolvedRevision.save();
         } finally {
@@ -699,10 +709,6 @@
         }
     }
 
-    private String getExpiration(ModuleRevisionId mrid) {
-        return String.valueOf(System.currentTimeMillis() + getTTL(mrid));
-    }
-
     public long getTTL(ModuleRevisionId mrid) {
         Long ttl = (Long) ttlRules.getRule(mrid);
         return ttl == null ? getDefaultTTL() : ttl.longValue();