Skip to content

Commit

Permalink
Merge pull request square#1760 from halizton/make_cache_init_public
Browse files Browse the repository at this point in the history
make the DiskLruCache's initialize() public through the Cache interface
  • Loading branch information
swankjesse committed Jul 22, 2015
2 parents 58fc2bc + 6e6c3e9 commit 291870e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 17 additions & 0 deletions okhttp/src/main/java/com/squareup/okhttp/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,23 @@ private void abortQuietly(DiskLruCache.Editor editor) {
}
}

/**
* Initialize the cache. This will include reading the journal files from
* the storage and building up the necessary in-memory cache information.
* <p>
* The initialization time may vary depending on the journal file size and
* the current actual cache size. The application needs to be aware of calling
* this function during the initialization phase and preferrably in a background
* worker thread.
* <p>
* Note that if the application chooses to not call this method to initialize
* the cache. By default, the okhttp will perform lazy initialization upon the
* first usage of the cache.
*/
public void initialize() throws IOException {
cache.initialize();
}

/**
* Closes the cache and deletes all of its stored values. This will delete
* all files in the cache directory including files that weren't created by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ public void run() {
this.executor = executor;
}

// Visible for testing.
void initialize() throws IOException {
public synchronized void initialize() throws IOException {
assert Thread.holdsLock(this);

if (initialized) {
Expand Down

0 comments on commit 291870e

Please sign in to comment.