Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Add public method to request the disk cache to cleanup #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/com/jakewharton/disklrucache/DiskLruCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -493,7 +499,7 @@ public synchronized long getMaxSize() {
*/
public synchronized void setMaxSize(long maxSize) {
this.maxSize = maxSize;
executorService.submit(cleanupCallable);
cleanupIfNeeded();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down