From 2dc073fc9260fe4472010a0e791e12ca3a92a254 Mon Sep 17 00:00:00 2001 From: Gabriel Herrera Date: Thu, 26 Dec 2013 14:11:02 -0600 Subject: [PATCH] Added "cleanupIfNeeded" public method Applications may need to explicitly request a disk cache cleanup in some circumstances. Signed-off-by: Gabriel Herrera --- .../com/jakewharton/disklrucache/DiskLruCache.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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(); } /**