Skip to content

Commit 8743ba1

Browse files
committed
feat: add SVG cache clear button to developer tools caches section
1 parent e20e261 commit 8743ba1

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/app/components/room-avatar/AvatarImage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export function getSvgCacheSize(): number {
1717
return svgBlobCache.size;
1818
}
1919

20+
/** Clear all SVG blob URLs from the module-level cache. */
21+
export function clearSvgBlobCache(): void {
22+
svgBlobCache.clear();
23+
}
24+
2025
type AvatarImageProps = {
2126
src: string;
2227
alt?: string;

src/app/features/settings/developer-tools/DevelopTools.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { copyToClipboard } from '$utils/dom';
1919
import { SequenceCardStyle } from '$features/settings/styles.css';
2020
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
21-
import { getSvgCacheSize } from '$components/room-avatar/AvatarImage';
21+
import { getSvgCacheSize, clearSvgBlobCache } from '$components/room-avatar/AvatarImage';
2222
import { SettingsSectionPage } from '../SettingsSectionPage';
2323
import { AccountData } from './AccountData';
2424
import { SyncDiagnostics } from './SyncDiagnostics';
@@ -75,6 +75,11 @@ export function DeveloperTools({ requestBack, requestClose }: DeveloperToolsProp
7575
setCacheStats(getBlobCacheStats());
7676
}, []);
7777

78+
const clearSvgCacheAction = useCallback(() => {
79+
clearSvgBlobCache();
80+
setSvgCacheSize(getSvgCacheSize());
81+
}, []);
82+
7883
const [clearSwCacheState, clearSwCacheAction] = useAsyncCallback<void, Error, []>(
7984
useCallback(async () => {
8085
await caches.delete('sable-media-sw-v1');
@@ -288,6 +293,18 @@ export function DeveloperTools({ requestBack, requestClose }: DeveloperToolsProp
288293
focusId="svg-cache"
289294
title="SVG Avatar Cache"
290295
description={`${svgCacheSize} ${svgCacheSize === 1 ? 'item' : 'items'} · processed SVG avatars, reused while app is open · cleared on reload`}
296+
after={
297+
<Button
298+
onClick={clearSvgCacheAction}
299+
variant="Secondary"
300+
fill="Soft"
301+
size="300"
302+
radii="300"
303+
outlined
304+
>
305+
<Text size="B300">Clear</Text>
306+
</Button>
307+
}
291308
/>
292309
<SettingTile
293310
focusId="clear-in-memory-cache"

0 commit comments

Comments
 (0)