[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Dec 5 17:12:21 UTC 2007


gordonp
Wed Dec  5 12:12:20 EST 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/meta
In directory dev.open-bio.org:/tmp/cvs-serv22646/src/main/org/biomoby/registry/meta

Modified Files:
	RegistryCache.java 
Log Message:
Added expiry argument to RDF file caching
moby-live/Java/src/main/org/biomoby/registry/meta RegistryCache.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/meta/RegistryCache.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/meta/RegistryCache.java	2007/06/09 22:15:06	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/meta/RegistryCache.java	2007/12/05 17:12:20	1.4
@@ -50,6 +50,15 @@
      * @param resourceName one of the resources listed in org.biomoby.shared.Central
      */
     public static void cacheRegistryOntology(Registry reg, String resourceName) throws Exception{
+	cacheRegistryOntology(reg, resourceName, -1);
+    }
+
+    /**
+     * Stores the given resource to a file for retrieval later with getOntologyFile().
+     *
+     * @param allowedAgeMillis if the hached file exists and is less than this many milliseconds old, a new version will not be downloaded, if zero or negative, overwrite is forced.
+     */
+    public static void cacheRegistryOntology(Registry reg, String resourceName, int allowedAgeMillis) throws Exception{
 	if(resourceName == null){
 	    throw new NullPointerException("The resource to be cached was null");
 	}
@@ -80,13 +89,20 @@
 	}
 	URL sourceURL = Registry.findResourceURL(reg, resourceName);
 
-	// Copy from URL to file, line-by-line
-	FileWriter cacheFileWriter = new FileWriter(cacheFile);
-	LineNumberReader r = new LineNumberReader(new InputStreamReader(sourceURL.openStream()));
-	for(String line = r.readLine(); line != null; line = r.readLine()){
-	    cacheFileWriter.write(line+"\n");
+	long currentTime = System.currentTimeMillis();
+
+	if(!cacheFile.exists() || 
+	   allowedAgeMillis <= 0 ||
+	   currentTime-cacheFile.lastModified() > allowedAgeMillis){
+	    // Copy from URL to file, line-by-line
+	    FileWriter cacheFileWriter = new FileWriter(cacheFile);
+	    LineNumberReader r = new LineNumberReader(new InputStreamReader(sourceURL.openStream()));
+	    for(String line = r.readLine(); line != null; line = r.readLine()){
+		cacheFileWriter.write(line+"\n");
+	    }
+	    
+	    cacheFileWriter.close();
 	}
-	cacheFileWriter.close();
     }
 
     public synchronized static Registry getDefaultRegistry(){




More information about the MOBY-guts mailing list