Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 28dbde9

Browse files
committed
Improve cache api
1 parent ac65012 commit 28dbde9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

server/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,10 @@ export class Application implements ServerApplication {
889889
}
890890
}
891891

892-
return await cache(url, { forceRefresh: this.#reloading, retryTimes: 10 })
892+
return await cache(url, {
893+
forceRefresh: this.#reloading,
894+
retryTimes: 10
895+
})
893896
}
894897

895898
private async precompile(

server/cache.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import { join } from 'https://deno.land/[email protected]/path/mod.ts'
44
import { existsFileSync } from '../shared/fs.ts'
55
import util from '../shared/util.ts'
66
import log from '../shared/log.ts'
7-
import { getDenoDir, reFullVersion } from './helper.ts'
7+
import { getDenoDir } from './helper.ts'
88

99
/** download and cache remote content */
1010
export async function cache(url: string, options?: { forceRefresh?: boolean, retryTimes?: number }) {
1111
const u = new URL(url)
1212
const { protocol, hostname, port, pathname, search } = u
1313
const isLocalhost = hostname === 'localhost' || hostname === '0.0.0.0' || hostname === '172.0.0.1'
14-
const versioned = reFullVersion.test(pathname)
15-
const reload = !!options?.forceRefresh || !versioned
1614
const cacheDir = join(
1715
await getDenoDir(),
1816
'deps',
@@ -23,7 +21,7 @@ export async function cache(url: string, options?: { forceRefresh?: boolean, ret
2321
const contentFile = join(cacheDir, hash)
2422
const metaFile = join(cacheDir, hash + '.metadata.json')
2523

26-
if (!reload && !isLocalhost && existsFileSync(contentFile) && existsFileSync(metaFile)) {
24+
if (!options?.forceRefresh && !isLocalhost && existsFileSync(contentFile) && existsFileSync(metaFile)) {
2725
const [content, meta] = await Promise.all([
2826
Deno.readFile(contentFile),
2927
Deno.readTextFile(metaFile),

0 commit comments

Comments
 (0)