feat: simplify caching — TanStack Query as single source of truth (#6075)
This commit is contained in:
1 parent
a5ec880eec
commit
f19033e0d5
187 files changed
+1013
-4712
No files matched your search
@@ -1,19 +1,10 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { createWidgetOptionsChannel } from "@homarr/redis";
|
||||
|
||||
import { createCachedRequestHandler } from "./lib/cached-request-handler";
|
||||
import type { ReleaseResponse, ReleasesRepositoryRequest } from "./release-providers";
|
||||
import { getLatestMatchingReleaseAsync } from "./release-providers";
|
||||
import { createRequestHandler } from "./lib/request-handler";
|
||||
|
||||
export const releasesRequestHandler = {
|
||||
handler: (itemOptions: ReleasesRepositoryRequest) =>
|
||||
createCachedRequestHandler<ReleaseResponse, ReleasesRepositoryRequest>({
|
||||
requestAsync: async (input) => await getLatestMatchingReleaseAsync(input),
|
||||
cacheDuration: dayjs.duration(5, "minutes"),
|
||||
queryKey: "repositoriesReleases",
|
||||
createRedisChannel(input, handlerOptions) {
|
||||
return createWidgetOptionsChannel<ReleaseResponse>("releases", handlerOptions.queryKey, input);
|
||||
},
|
||||
}).handler(itemOptions),
|
||||
};
|
||||
export const releasesRequestHandler = createRequestHandler<ReleaseResponse, ReleasesRepositoryRequest>({
|
||||
async requestAsync(input) {
|
||||
return await getLatestMatchingReleaseAsync(input);
|
||||
},
|
||||
cacheTtlMs: 5 * 60 * 1000,
|
||||
});
|
||||
Reference in new issue
Block a user