Server

getServerFunctionMeta

编辑此页面

getServerFunctionMeta 返回一个特定于函数的 id 字符串,当服务器函数在多个 CPU 核心或工作进程上并行运行时,这个 id 在所有实例中保持稳定。

这个 id 属性在不同的构建之间可能会且_一定会_发生变化。

import { getServerFunctionMeta } from "@solidjs/start/server";
// 或者一些内存数据库
const appCache: any = globalThis;
const counter = async () => {
"use server";
const { id } = getServerFunctionMeta()!;
const key = `counter_${id}`;
appCache[key] = appCache[key] ?? 0;
appCache[key]++;
return appCache[key] as number;
};

参数

getServerFunctionMeta(): { id: string }

报告此页面问题