From 2aa3a601e0aa619d630228027eff52ba61239a15 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 12 Sep 2014 00:07:27 +0200 Subject: [PATCH] Cache now gets removed after 3 days This is based on the latest modification date, so it depends on the file when it gets removed. --- .../src/org/parabot/core/Directories.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/parabotv2/src/org/parabot/core/Directories.java b/parabotv2/src/org/parabot/core/Directories.java index a60a43c..b1ff074 100644 --- a/parabotv2/src/org/parabot/core/Directories.java +++ b/parabotv2/src/org/parabot/core/Directories.java @@ -35,6 +35,8 @@ public class Directories { cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/")); cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/")); Core.verbose("Directories cached."); + + clearCache(259200); } /** @@ -174,4 +176,20 @@ public class Directories { return temp; } + /** + * Clears the cache based on the latest modification + * @param remove A long that represents the amount of seconds that a file may have since the latest modification + */ + private static void clearCache(int remove){ + File[] cache = getCachePath().listFiles(); + if (cache != null){ + for (File f : cache){ + if (f != null && System.currentTimeMillis() / 1000 - f.lastModified() / 1000 > remove){ + Core.verbose("Clearing " + f.getName() + " from cache..."); + f.delete(); + } + } + } + } + }