|
1 | | -// import { S3 } from "./s3-api.ts"; |
2 | | -// import { ApiFactory } from "../../lib/client/mod.ts"; |
3 | | -import { AsyncTracer, Span } from "./tracer.ts"; |
| 1 | +import { LogicTracer, Span } from "./tracer.ts"; |
4 | 2 |
|
5 | | -// can maybe replace this whole dep with deno edge cache once it's out of beta |
6 | 3 | import type { Cache } from "./httpcache/mod.ts"; |
7 | 4 | import { inMemoryCache } from "./httpcache/in_memory.ts"; |
8 | | -// import { s3Cache } from "./cache-s3.ts"; |
9 | | -import { platformCache } from "./cache-platform.ts"; |
10 | | - |
11 | | -// const s3Api = new ApiFactory({ |
12 | | -// region: Deno.env.get('HTTPCACHE_S3_REGION') || 'us-east-2', |
13 | | -// }).makeNew(S3); |
| 5 | +import { platformCache } from "./httpcache/platform.ts"; |
14 | 6 |
|
15 | 7 | const caches: Array<Cache> = [ |
16 | 8 | inMemoryCache(40), |
17 | 9 | await platformCache(), |
18 | | - // s3Cache(s3Api, Deno.env.get('HTTPCACHE_S3_BUCKET') || 'deno-httpcache'), |
19 | 10 | ]; |
20 | 11 | const cacheLabels = ['in-memory', 'platform', 's3']; |
21 | 12 |
|
22 | | -const tracer = new AsyncTracer('cached-fetch'); |
| 13 | +const tracer = new LogicTracer({ |
| 14 | + name: 'cached-fetch', |
| 15 | +}); |
23 | 16 |
|
24 | 17 | export async function cachedFetch(mode: 'immutable' | 'mutable', label: string, url: string) { |
25 | | - return await tracer.runAsyncSpan(`fetch ${label}`, { |
26 | | - 'cache.label': label, |
27 | | - 'cache.mode': mode, |
28 | | - }, span => cachedFetchInner(mode, label, url, span)); |
| 18 | + return await tracer.asyncSpan(`fetch ${label}`, { |
| 19 | + attributes: { |
| 20 | + 'cache.label': label, |
| 21 | + 'cache.mode': mode, |
| 22 | + }, |
| 23 | + }, span => cachedFetchInner(mode, url, span!)); |
29 | 24 | } |
30 | | -async function cachedFetchInner(mode: 'immutable' | 'mutable', label: string, url: string, span: Span) { |
| 25 | +async function cachedFetchInner(mode: 'immutable' | 'mutable', url: string, span: Span) { |
31 | 26 |
|
32 | 27 | for (const [cacheIdx, cache] of caches.entries()) { |
33 | 28 | const cached = await cache.match(url).catch(err => { |
|
0 commit comments