Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

reload caches on cache folder change

Abhinav0293de0c8027
diff --git a/apps/photos/src/components/Sidebar/Preferences/CacheDirectory.tsx b/apps/photos/src/components/Sidebar/Preferences/CacheDirectory.tsx
index 08cd75e0d1..b0773ab2f7 100644
--- a/apps/photos/src/components/Sidebar/Preferences/CacheDirectory.tsx
+++ b/apps/photos/src/components/Sidebar/Preferences/CacheDirectory.tsx
@@ -9,6 +9,7 @@ import MenuSectionTitle from 'components/Menu/MenuSectionTitle';
import { t } from 'i18next';
import isElectron from 'is-electron';
import { useEffect, useState } from 'react';
+import DownloadManager from 'services/download';
export default function CacheDirectory() {
const [cacheDirectory, setCacheDirectory] = useState(undefined);
@@ -36,6 +37,7 @@ export default function CacheDirectory() {
addLogLine(`Export folder changed to ${newFolder}`);
await ElectronAPIs.setCustomCacheDirectory(newFolder);
setCacheDirectory(newFolder);
+ await DownloadManager.reloadCaches();
} catch (e) {
logError(e, 'handleCacheDirectoryChange failed');
}
diff --git a/apps/photos/src/services/download/index.ts b/apps/photos/src/services/download/index.ts
index 1abcc93016..5a7c93672f 100644
--- a/apps/photos/src/services/download/index.ts
+++ b/apps/photos/src/services/download/index.ts
@@ -59,7 +59,7 @@ export interface DownloadClient {
const FILE_CACHE_LIMIT = 5 * 1024 * 1024 * 1024; // 5GB
-class DownloadManager {
+class DownloadManagerImpl {
private ready: boolean = false;
private downloadClient: DownloadClient;
private thumbnailCache?: LimitedCache;
@@ -111,6 +111,11 @@ class DownloadManager {
this.progressUpdater = progressUpdater;
}
+ async reloadCaches() {
+ this.thumbnailCache = await openThumbnailCache();
+ this.diskFileCache = isElectron() && (await openDiskFileCache());
+ }
+
private async getCachedThumbnail(fileID: number) {
try {
const cacheResp: Response = await this.thumbnailCache?.match(
@@ -531,7 +536,9 @@ class DownloadManager {
};
}
-export default new DownloadManager();
+const DownloadManager = new DownloadManagerImpl();
+
+export default DownloadManager;
async function openThumbnailCache() {
try {