CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/get-title.ts
Views: 687
1
/*
2
Get title *and* color of a compute server you own.
3
This is mainly meant to be used for purchase history, etc.,
4
so the result is cached for a few minutes, and it's
5
an error if you don't own the server.
6
*/
7
8
import LRU from "lru-cache";
9
import { getTitle as getTitleViaApi } from "./api";
10
11
const cache = new LRU<
12
number,
13
{ title: string; color: string; project_specific_id: number }
14
>({
15
max: 1000,
16
ttl: 1000 * 30,
17
});
18
19
export default async function getTitle(
20
compute_server_id: number,
21
): Promise<{ title: string; color: string; project_specific_id: number }> {
22
if (cache.has(compute_server_id)) {
23
return cache.get(compute_server_id)!;
24
}
25
const x = await getTitleViaApi({ id: compute_server_id });
26
cache.set(compute_server_id, x);
27
return x;
28
}
29
30