Add error logs for server functions. Add cache dynamic function.

This commit is contained in:
2026-03-27 05:22:31 +01:00
parent 572f739b5c
commit 950bdc3dca
10 changed files with 157 additions and 32 deletions
@@ -0,0 +1,29 @@
import _ from "lodash";
import { log } from "../../../utils/log";
import writeCache from "../../cache/write-cache";
export default async function generateWebPageGetCachePage({ module, routeParams, serverRes, root_module, html, }) {
const config = _.merge(root_module?.config, module.config);
const cache_page = config?.cachePage || serverRes?.cachePage || false;
const expiry_seconds = config?.cacheExpiry || serverRes?.cacheExpiry;
if (cache_page && routeParams?.url) {
try {
const is_cache = typeof cache_page == "boolean"
? cache_page
: await cache_page({ ctx: routeParams, serverRes });
if (!is_cache) {
return false;
}
const key = routeParams.url.pathname + (routeParams.url.search || "");
writeCache({
key,
value: html,
paradigm: "html",
expiry_seconds,
});
}
catch (error) {
log.error(`Error writing Cache => ${error.message}\n`, error);
}
}
return true;
}