Skip to content

Commit 88ac7e3

Browse files
committed
ref: Reduced cache JNI calls
1 parent 9866da9 commit 88ac7e3

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.nativescript.https;
2+
3+
import okhttp3.Cache;
4+
5+
public class CacheUtils {
6+
public static void removeCachedResponse(String url, Cache cache) {
7+
final Iterator<String> it = cache.urls();
8+
9+
while (it.hasNext()) {
10+
String cacheUrl = it.next();
11+
12+
if (cacheUrl.equals(url)) {
13+
it.remove();
14+
break;
15+
}
16+
}
17+
}
18+
}

packages/https/platforms/android/native-api-usage.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"java.net:CookiePolicy",
3131
"com.nativescript.https:QuotePreservingCookieJar",
3232
"com.nativescript.https:CacheInterceptor",
33+
"com.nativescript.https:CacheUtils",
3334
"com.nativescript.https:OkHttpResponse",
3435
"java.util:Collections",
3536
"java.security.cert:CertificateFactory",

src/https/request.android.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,8 @@ export function clearCache() {
5252
}
5353

5454
export function removeCachedResponse(url: string) {
55-
if (!cache) {
56-
return;
57-
}
58-
59-
const iterator = cache.urls();
60-
61-
while (iterator.hasNext()) {
62-
const cacheUrl = iterator.next();
63-
if (cacheUrl === url) {
64-
iterator.remove();
65-
break;
66-
}
55+
if (cache) {
56+
com.nativescript.https.CacheUtils.removeCachedResponse(url, cache);
6757
}
6858
}
6959

src/https/typings/android.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ declare namespace com {
77
export class CacheInterceptor {
88
public static INTERCEPTOR: okhttp3.Interceptor;
99
}
10+
export class CacheUtils {
11+
static removeCachedResponse(url: string, cache: okhttp3.Cache): void;
12+
}
1013
export class OkHttpResponse {
1114
progressCallback: OkHttpResponse.OkHttpResponseProgressCallback;
1215
closeCallback: OkHttpResponse.OkHttpResponseCloseCallback;

0 commit comments

Comments
 (0)