Skip to content

Commit

Permalink
store/cockpitApi: invalidate cache after building an image
Browse files Browse the repository at this point in the history
With the custom query functions the cached data from getComposes and
getBlueprintComposes doesn't get invalidated. Luckily RTKQuery provides
a mechanism to invalidate the cache after a mutation.
  • Loading branch information
croissanne committed Jan 24, 2025
1 parent 716568d commit df3f978
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/store/cockpitApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
ComposeBlueprintApiResponse,
ComposeBlueprintApiArg
>({
invalidatesTags: ['Composes'],
queryFn: async ({ id: filename }) => {
const blueprintsDir = await getBlueprintsPath();
const file = cockpit.file(
Expand Down Expand Up @@ -260,6 +261,7 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
},
}),
getComposes: builder.query<GetComposesApiResponse, GetComposesApiArg>({
providesTags: ['Composes'],
queryFn: async () => {
const blueprintsDir = await getBlueprintsPath();
const info = await fsinfo(blueprintsDir, ['entries'], {
Expand Down Expand Up @@ -291,6 +293,7 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
GetBlueprintComposesApiResponse,
GetBlueprintComposesApiArg
>({
providesTags: ['Composes'],
queryFn: async (queryArgs) => {
const composes = await readComposes(queryArgs.id);
return {
Expand Down
1 change: 1 addition & 0 deletions src/store/emptyCockpitApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
export const emptyCockpitApi = createApi({
reducerPath: 'cockpitApi',
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
tagTypes: ['Composes'],
endpoints: () => ({}),
});

0 comments on commit df3f978

Please sign in to comment.