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.
This commit is contained in:
JKetelaar
2014-09-12 00:07:27 +02:00
parent 92217cc328
commit 2aa3a601e0
@@ -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();
}
}
}
}
}