/* eslint-disable no-console */ import Inject, { RegisterSingleton, ServiceObject } from "@entity-access/entity-access/dist/di/di.js"; import { join } from "path"; import BaseDiskCache from "@entity-access/server-pages/dist/cache/BaseDiskCache.js"; import { globalEnv } from "../../../common/globalEnv.js"; import MessagingService from "../message-events/MessagingService.js"; import { ObjectCache } from "../../../common/cacheFor.js"; @RegisterSingleton export default class SiteDiskContentCache extends ServiceObject { @Inject ms: MessagingService; cache: ObjectCache = new ObjectCache(5*60*1000); htmlCache = new BaseDiskCache({ root: join(globalEnv.tmpDir, "site-html-cache", "html"), keepTTLSeconds: 7*24*60*60 }); postInit() { this.ms.snapshotRefresh.on(({ folderID }) => { this.cache.clear(); }); this.ms.configurationChanged.on(({ name }) => { if(/package/i.test(name)) { this.cache.clear(); this.htmlCache.clear().catch(console.error); } }); } }