From 8928e8854e2d7f0ff0e750c3573778dfbe58c53b Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 25 May 2019 19:57:33 +0200 Subject: [PATCH] allow clean disk cache --- src/be/nikiroo/fanfix/Instance.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index cacbbfe..391bb2f 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -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 -- 2.27.0