allow clean disk cache
authorNiki Roo <niki@nikiroo.be>
Sat, 25 May 2019 17:57:33 +0000 (19:57 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 25 May 2019 17:57:33 +0000 (19:57 +0200)
src/be/nikiroo/fanfix/Instance.java

index cacbbfe33320c32df5002563105e643a9ac8c86a..391bb2f5b19c22a93e5d43838128e6f09fd61713 100644 (file)
@@ -40,6 +40,8 @@ public class Instance {
        private static TraceHandler tracer;
        private static TempFiles tempFiles;
 
+       private static File cacheDir;
+
        static {
                // Before we can configure it:
                tracer = new TraceHandler(true, checkEnv("DEBUG"), checkEnv("DEBUG"));
@@ -71,17 +73,17 @@ public class Instance {
                lib = createDefaultLibrary(remoteDir);
 
                // create cache
-               File tmp = getFile(Config.CACHE_DIR);
-               if (tmp == null) {
+               cacheDir = getFile(Config.CACHE_DIR);
+               if (cacheDir == null) {
                        // Could have used: System.getProperty("java.io.tmpdir")
-                       tmp = new File(configDir, "tmp");
+                       cacheDir = new File(configDir, "tmp");
                }
                String ua = config.getString(Config.USER_AGENT);
                try {
                        int hours = config.getInteger(Config.CACHE_MAX_TIME_CHANGING, -1);
                        int hoursLarge = config
                                        .getInteger(Config.CACHE_MAX_TIME_STABLE, -1);
-                       cache = new DataLoader(tmp, ua, hours, hoursLarge);
+                       cache = new DataLoader(cacheDir, ua, hours, hoursLarge);
                } catch (IOException e) {
                        tracer.error(new IOException(
                                        "Cannot create cache (will continue without cache)", e));
@@ -338,6 +340,14 @@ public class Instance {
                return tempFiles;
        }
 
+       /**
+        * Delete all the cache files, can be very long...
+        */
+       public static void PATCH_emptyCache() {
+               IOUtils.deltree(cacheDir);
+               cacheDir.mkdirs();
+       }
+
        /**
         * The configuration directory (will check, in order of preference,
         * {@link Bundles#getDirectory()}, the system properties, the environment