diff --git a/src/main/java/com/jakewharton/disklrucache/DiskLruCache.java b/src/main/java/com/jakewharton/disklrucache/DiskLruCache.java index b29a9d0..6241b84 100644 --- a/src/main/java/com/jakewharton/disklrucache/DiskLruCache.java +++ b/src/main/java/com/jakewharton/disklrucache/DiskLruCache.java @@ -381,6 +381,12 @@ private synchronized void rebuildJournal() throws IOException { new OutputStreamWriter(new FileOutputStream(journalFile, true), Util.US_ASCII)); } + public void cleanupIfNeeded() { + if (size > maxSize || journalRebuildRequired()) { + executorService.submit(cleanupCallable); + } + } + private static void deleteIfExists(File file) throws IOException { if (file.exists() && !file.delete()) { throw new IOException(); @@ -493,7 +499,7 @@ public synchronized long getMaxSize() { */ public synchronized void setMaxSize(long maxSize) { this.maxSize = maxSize; - executorService.submit(cleanupCallable); + cleanupIfNeeded(); } /** @@ -554,10 +560,7 @@ private synchronized void completeEdit(Editor editor, boolean success) throws IO journalWriter.write(REMOVE + ' ' + entry.key + '\n'); } journalWriter.flush(); - - if (size > maxSize || journalRebuildRequired()) { - executorService.submit(cleanupCallable); - } + cleanupIfNeeded(); } /**