Skip to content

Commit

Permalink
feat(ui): add button to clear model cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary Hipp authored and hipsterusername committed Jan 30, 2025
1 parent cc9d215 commit 64475b8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
5 changes: 5 additions & 0 deletions invokeai/frontend/web/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@
"disableFailed": "Problem Disabling Invocation Cache",
"useCache": "Use Cache"
},
"modelCache": {
"clear": "Clear Model Cache",
"clearSucceeded": "Model Cache Cleared",
"clearFailed": "Problem Clearing Model Cache"
},
"gallery": {
"gallery": "Gallery",
"alwaysShowImageSizeBadge": "Always Show Image Size Badge",
Expand Down
1 change: 1 addition & 0 deletions invokeai/frontend/web/src/app/types/invokeai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type AppFeature =
| 'pauseQueue'
| 'resumeQueue'
| 'invocationCache'
| 'modelCache'
| 'bulkDownload'
| 'starterModels'
| 'hfToken';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Button } from '@invoke-ai/ui-library';
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
import { toast } from 'features/toast/toast';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useEmptyModelCacheMutation } from 'services/api/endpoints/models';

const ClearModelCacheButton = () => {
const isModelCacheEnabled = useFeatureStatus('modelCache');
const [emptyModelCache, { isLoading }] = useEmptyModelCacheMutation();
const { t } = useTranslation();

const handleClearCache = useCallback(async () => {
try {
await emptyModelCache().unwrap();
toast({
status: 'success',
title: t('modelCache.clearSucceeded'),
});
} catch (error) {
toast({
status: 'error',
title: t('modelCache.clearFailed'),
});
}
}, [emptyModelCache, t]);

if (!isModelCacheEnabled) {
return <></>;
}

return (
<Button size="sm" colorScheme="red" onClick={handleClearCache} isLoading={isLoading}>
{t('modelCache.clear')}
</Button>
);
};

export default memo(ClearModelCacheButton);
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable i18next/no-literal-string */
import { ButtonGroup, Flex } from '@invoke-ai/ui-library';
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
import { memo } from 'react';

import ClearModelCacheButton from './ClearModelCacheButton';
import ClearQueueButton from './ClearQueueButton';
import PauseProcessorButton from './PauseProcessorButton';
import PruneQueueButton from './PruneQueueButton';
Expand All @@ -11,19 +13,22 @@ const QueueTabQueueControls = () => {
const isPauseEnabled = useFeatureStatus('pauseQueue');
const isResumeEnabled = useFeatureStatus('resumeQueue');
return (
<Flex layerStyle="first" borderRadius="base" p={2} gap={2}>
{isPauseEnabled || isResumeEnabled ? (
<Flex flexDir="column" layerStyle="first" borderRadius="base" p={2} gap={2}>
<Flex gap={2}>
{isPauseEnabled || isResumeEnabled ? (
<ButtonGroup w={28} orientation="vertical" size="sm">
{isResumeEnabled ? <ResumeProcessorButton /> : <></>}
{isPauseEnabled ? <PauseProcessorButton /> : <></>}
</ButtonGroup>
) : (
<></>
)}
<ButtonGroup w={28} orientation="vertical" size="sm">
{isResumeEnabled ? <ResumeProcessorButton /> : <></>}
{isPauseEnabled ? <PauseProcessorButton /> : <></>}
<PruneQueueButton />
<ClearQueueButton />
</ButtonGroup>
) : (
<></>
)}
<ButtonGroup w={28} orientation="vertical" size="sm">
<PruneQueueButton />
<ClearQueueButton />
</ButtonGroup>
</Flex>
<ClearModelCacheButton />
</Flex>
);
};
Expand Down
4 changes: 4 additions & 0 deletions invokeai/frontend/web/src/services/api/endpoints/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ export const modelsApi = api.injectEndpoints({
}
},
}),
emptyModelCache: build.mutation<void, void>({
query: () => ({ url: buildModelsUrl('empty_model_cache'), method: 'POST' }),
}),
}),
});

Expand All @@ -295,6 +298,7 @@ export const {
useGetStarterModelsQuery,
useGetHFTokenStatusQuery,
useSetHFTokenMutation,
useEmptyModelCacheMutation,
} = modelsApi;

export const selectModelConfigsQuery = modelsApi.endpoints.getModelConfigs.select();

0 comments on commit 64475b8

Please sign in to comment.