import "../../_dnt.polyfills.js"; import * as dntShim from "../../_dnt.shims.js"; import * as fs from "../../deps/std/fs.js" import * as path from "../../deps/std/path.js" import { CacheBase } from "./base.js" export class FsCache extends CacheBase { constructor(readonly location: string, signal: AbortSignal) { super(signal) } async _has(key: string) { const file = path.join(this.location, key) try { await dntShim.Deno.lstat(file) return true } catch { return false } } async _getRaw(key: string, init: () => Promise) { const file = path.join(this.location, key) try { return await dntShim.Deno.readFile(file) } catch (e) { if (!(e instanceof dntShim.Deno.errors.NotFound)) throw e const content = await init() await fs.ensureDir(path.dirname(file)) await dntShim.Deno.writeFile(file, content) return content } } }