MCPcopy Create free account
hub / github.com/msgbyte/tailchat / buildCachedRequest

Function buildCachedRequest

client/shared/cache/utils.ts:14–48  ·  view source on GitHub ↗
(
  name: string,
  fn: F,
  options?: FetchQueryOptions
)

Source from the content-addressed store, hash-verified

12 * })
13 */
14export function buildCachedRequest<R, F extends (...args: any) => Promise<R>>(
15 name: string,
16 fn: F,
17 options?: FetchQueryOptions
18): F & {
19 /**
20 * 根据name重新获取数据
21 */
22 refetch: () => Promise<void>;
23 /**
24 * 清空name相关缓存
25 */
26 clearCache: () => void;
27} {
28 const req = ((...args: any) => {
29 return queryClient.fetchQuery(
30 [name, JSON.stringify(args)],
31 () => fn(...args),
32 options
33 );
34 }) as any;
35
36 const refetch = () => {
37 return queryClient.refetchQueries([name]);
38 };
39
40 const clearCache = () => {
41 queryClient.removeQueries([name]);
42 };
43
44 req.refetch = refetch;
45 req.clearCache = clearCache;
46
47 return req;
48}

Callers 2

common.tsFile · 0.90
user.tsFile · 0.90

Calls 1

fnFunction · 0.50

Tested by

no test coverage detected