Skip to content

Commit 039950a

Browse files
committed
updates
1 parent 9a73dcd commit 039950a

File tree

7 files changed

+19
-42
lines changed

7 files changed

+19
-42
lines changed

cache_test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ async function setup() {
1212
});
1313
const denoDir = new DenoDir(tempdir);
1414
const fileFetcher = new FileFetcher(
15-
() => {
16-
return denoDir.createHttpCache();
17-
},
15+
denoDir.createHttpCache(),
1816
"use",
1917
true,
2018
);

deno_dir.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class DenoDir {
2626

2727
createHttpCache(
2828
options?: { vendorRoot?: string | URL; readOnly?: boolean },
29-
): Promise<HttpCache> {
29+
): HttpCache {
3030
return HttpCache.create({
3131
root: join(this.root, "remote"),
3232
vendorRoot: options?.vendorRoot == null

file_fetcher.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,18 @@ export class FileFetcher {
116116
#authTokens: AuthTokens;
117117
#cache = new Map<string, LoadResponse>();
118118
#cacheSetting: CacheSetting;
119-
#httpCache: HttpCache | undefined;
120-
#httpCachePromise: Promise<HttpCache> | undefined;
121-
#httpCacheFactory: () => Promise<HttpCache>;
119+
#httpCache: HttpCache;
122120

123121
constructor(
124-
httpCacheFactory: () => Promise<HttpCache>,
122+
httpCache: HttpCache,
125123
cacheSetting: CacheSetting = "use",
126124
allowRemote = true,
127125
) {
128126
Deno.permissions.request({ name: "env", variable: "DENO_AUTH_TOKENS" });
129127
this.#authTokens = new AuthTokens(Deno.env.get("DENO_AUTH_TOKENS"));
130128
this.#allowRemote = allowRemote;
131129
this.#cacheSetting = cacheSetting;
132-
this.#httpCacheFactory = httpCacheFactory;
130+
this.#httpCache = httpCache;
133131
}
134132

135133
async #fetchBlobDataUrl(
@@ -300,7 +298,7 @@ export class FileFetcher {
300298
const response = await this.#fetchBlobDataUrl(
301299
specifier,
302300
this.#resolveOptions(options),
303-
await this.#resolveHttpCache(),
301+
this.#httpCache,
304302
);
305303
await this.#cache.set(specifier.toString(), response);
306304
return response;
@@ -312,7 +310,7 @@ export class FileFetcher {
312310
const response = await this.#fetchRemoteOnce(
313311
specifier,
314312
this.#resolveOptions(options),
315-
await this.#resolveHttpCache(),
313+
this.#httpCache,
316314
);
317315
if (response) {
318316
await this.#cache.set(specifier.toString(), response);
@@ -326,20 +324,6 @@ export class FileFetcher {
326324
options.cacheSetting = options.cacheSetting ?? this.#cacheSetting;
327325
return options as ResolvedFetchOptions;
328326
}
329-
330-
#resolveHttpCache(): Promise<HttpCache> {
331-
if (this.#httpCache != null) {
332-
return Promise.resolve(this.#httpCache);
333-
}
334-
if (!this.#httpCachePromise) {
335-
this.#httpCachePromise = this.#httpCacheFactory().then((cache) => {
336-
this.#httpCache = cache;
337-
this.#httpCachePromise = undefined;
338-
return cache;
339-
});
340-
}
341-
return this.#httpCachePromise;
342-
}
343327
}
344328

345329
export async function fetchWithRetries(

file_fetcher_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Deno.test({
88
name: "FileFetcher",
99
async fn() {
1010
const denoDir = new DenoDir();
11-
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
11+
const fileFetcher = new FileFetcher(denoDir.createHttpCache());
1212
const graph = await createGraph("https://deno.land/x/oak@v10.5.1/mod.ts", {
1313
load(specifier) {
1414
return fileFetcher.fetch(new URL(specifier));
@@ -23,7 +23,7 @@ Deno.test({
2323
name: "FileFetcher - bad checksum no cache",
2424
async fn() {
2525
const denoDir = new DenoDir();
26-
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
26+
const fileFetcher = new FileFetcher(denoDir.createHttpCache());
2727
{
2828
// should error
2929
await assertRejects(async () => {
@@ -50,7 +50,7 @@ Deno.test({
5050
name: "FileFetcher - bad checksum reload",
5151
async fn() {
5252
const denoDir = new DenoDir();
53-
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
53+
const fileFetcher = new FileFetcher(denoDir.createHttpCache());
5454
await assertRejects(async () => {
5555
await fileFetcher.fetchOnce(
5656
new URL("https://deno.land/x/oak@v10.5.1/mod.ts"),
@@ -67,7 +67,7 @@ Deno.test({
6767
name: "FileFetcher - good checksum reload",
6868
async fn() {
6969
const denoDir = new DenoDir();
70-
const fileFetcher = new FileFetcher(() => denoDir.createHttpCache());
70+
const fileFetcher = new FileFetcher(denoDir.createHttpCache());
7171
await fileFetcher.fetchOnce(
7272
new URL("https://deno.land/x/oak@v10.5.1/mod.ts"),
7373
{

http_cache.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { isAbsolute } from "@std/path";
44
import { assert } from "./util.ts";
5-
import {
6-
GlobalHttpCache,
7-
LocalHttpCache,
8-
} from "./lib/deno_cache_dir_wasm.js";
5+
import { GlobalHttpCache, LocalHttpCache } from "./lib/deno_cache_dir_wasm.js";
96

107
export interface HttpCacheCreateOptions {
118
root: string;
@@ -37,7 +34,7 @@ export class HttpCache implements Disposable {
3734
this.#readOnly = readOnly;
3835
}
3936

40-
static async create(options: HttpCacheCreateOptions): Promise<HttpCache> {
37+
static create(options: HttpCacheCreateOptions): HttpCache {
4138
assert(isAbsolute(options.root), "Root must be an absolute path.");
4239

4340
if (options.vendorRoot != null) {

mod.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ export function createCache({
9898
}: CacheOptions = {}): Loader {
9999
const denoDir = new DenoDir(root);
100100
const fileFetcher = new FileFetcher(
101-
() => {
102-
return denoDir.createHttpCache({
103-
readOnly,
104-
vendorRoot,
105-
});
106-
},
101+
denoDir.createHttpCache({
102+
readOnly,
103+
vendorRoot,
104+
}),
107105
cacheSetting,
108106
allowRemote,
109107
);

rs_lib/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ use sys_traits::impls::wasm_string_to_path;
1515
use url::Url;
1616
use wasm_bindgen::prelude::*;
1717

18+
use deno_cache_dir::CacheEntry;
1819
use deno_cache_dir::CacheReadFileError;
1920
use deno_cache_dir::Checksum;
20-
use deno_cache_dir::HttpCache;
21-
use deno_cache_dir::CacheEntry;
2221
use deno_cache_dir::GlobalToLocalCopy;
2322
use deno_cache_dir::HeadersMap;
23+
use deno_cache_dir::HttpCache;
2424

2525
#[wasm_bindgen]
2626
pub fn url_to_filename(url: &str) -> Result<String, JsValue> {

0 commit comments

Comments
 (0)