-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep onlyRetrieveFromCache and normal requests running independently.
This prevents cases where using onlyRetrieveFromCache might block a request on an RPC if a request was already pending without onlyRetrieveFromCache being set. However, this change does now mean that it's possible a resource will be loaded from the disk cache twice simultaneously because onlyRetrieveFromCache requests are no longer deduped with normal requests. We expect this case to be rare, and the consequences are an efficiency issue rather than a correctness problem, so we're still probably better off with this change. Future work might include attempting to cancel and notify any normal requests if an onlyRetrieveFromCache requests completes with the same key will the normal request is running. Fixes #2428.
- Loading branch information
Showing
15 changed files
with
521 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
library/src/main/java/com/bumptech/glide/load/engine/Jobs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.bumptech.glide.load.engine; | ||
|
||
import android.support.annotation.VisibleForTesting; | ||
import com.bumptech.glide.load.Key; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
final class Jobs { | ||
private final Map<Key, EngineJob<?>> jobs = new HashMap<>(); | ||
private final Map<Key, EngineJob<?>> onlyCacheJobs = new HashMap<>(); | ||
|
||
@VisibleForTesting | ||
Map<Key, EngineJob<?>> getAll() { | ||
return Collections.unmodifiableMap(jobs); | ||
} | ||
|
||
EngineJob<?> get(Key key, boolean onlyRetrieveFromCache) { | ||
return getJobMap(onlyRetrieveFromCache).get(key); | ||
} | ||
|
||
void put(Key key, EngineJob<?> job) { | ||
getJobMap(job.onlyRetrieveFromCache()).put(key, job); | ||
} | ||
|
||
void removeIfCurrent(Key key, EngineJob<?> expected) { | ||
Map<Key, EngineJob<?>> jobMap = getJobMap(expected.onlyRetrieveFromCache()); | ||
if (expected.equals(jobMap.get(key))) { | ||
jobMap.remove(key); | ||
} | ||
} | ||
|
||
private Map<Key, EngineJob<?>> getJobMap(boolean onlyRetrieveFromCache) { | ||
return onlyRetrieveFromCache ? onlyCacheJobs : jobs; | ||
} | ||
} |
Oops, something went wrong.