mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-15 13:55:03 -05:00
Add caching
This commit is contained in:
parent
58ee860cc4
commit
a19aa76369
@ -23,24 +23,26 @@ public enum ThumbnailProvider {
|
|||||||
byte[][] response = new byte[ids.length][];
|
byte[][] response = new byte[ids.length][];
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
for (int i = 0; i < request.length; i++) {
|
for (int i = 0; i < response.length; i++) {
|
||||||
response[i] = (byte[]) cache.get(ids[i]);
|
response[i] = (byte[]) cache.get(ids[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < request.length; i++) {
|
for (int i = 0; i < response.length; i++) {
|
||||||
if (response[i] == null) {
|
if (response[i] == null) {
|
||||||
HttpRequest r = HttpRequest.newBuilder(getThumbnailURL(ids[i])).build();
|
HttpRequest r = HttpRequest.newBuilder(getThumbnailURL(ids[i])).build();
|
||||||
request[i] = http.sendAsync(r, BodyHandlers.ofByteArray());
|
request[i] = http.sendAsync(r, BodyHandlers.ofByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < request.length; i++) {
|
for (int i = 0; i < response.length; i++) {
|
||||||
if (response[i] == null) {
|
if (request[i] != null) {
|
||||||
HttpResponse<byte[]> r = request[i].get();
|
HttpResponse<byte[]> r = request[i].get();
|
||||||
if (r.statusCode() == 200) {
|
if (r.statusCode() == 200) {
|
||||||
response[i] = r.body();
|
response[i] = r.body();
|
||||||
cache.put(ids[i], response[i]);
|
} else {
|
||||||
|
response[i] = new byte[0];
|
||||||
}
|
}
|
||||||
|
cache.put(ids[i], response[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user