You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/cache/cache.ts

27 lines
659 B
TypeScript

import { ChatConverseInfo, fetchConverseInfo } from '../model/converse';
import { fetchUserInfo, UserBaseInfo } from '../model/user';
import { queryClient } from './index';
function buildCacheFactory<T>(
scope: string,
fetcher: (id: string) => Promise<T>
) {
return async (id: string): Promise<T> => {
const data = await queryClient.fetchQuery([scope, id], () => fetcher(id));
return data;
};
}
/**
* 获取缓存的用户信息
*/
export const getCachedUserInfo = buildCacheFactory<UserBaseInfo>(
'user',
fetchUserInfo
);
export const getCachedConverseInfo = buildCacheFactory<ChatConverseInfo>(
'converse',
fetchConverseInfo
);