diff --git a/web/apps/photos/src/components/ml/PeopleList.tsx b/web/apps/photos/src/components/ml/PeopleList.tsx index eddc5f085..97fa504a0 100644 --- a/web/apps/photos/src/components/ml/PeopleList.tsx +++ b/web/apps/photos/src/components/ml/PeopleList.tsx @@ -1,4 +1,4 @@ -import { cached } from "@/next/cache"; +import { cached } from "@/next/blob-cache"; import { ensureLocalUser } from "@/next/local-user"; import log from "@/next/log"; import { Skeleton, styled } from "@mui/material"; diff --git a/web/apps/photos/src/services/download/index.ts b/web/apps/photos/src/services/download/index.ts index c647e39fb..aaaf788f2 100644 --- a/web/apps/photos/src/services/download/index.ts +++ b/web/apps/photos/src/services/download/index.ts @@ -1,4 +1,4 @@ -import { openCache, type EnteCache } from "@/next/cache"; +import { openCache, type BlobCache } from "@/next/blob-cache"; import log from "@/next/log"; import { APPS } from "@ente/shared/apps/constants"; import ComlinkCryptoWorker from "@ente/shared/crypto"; @@ -55,13 +55,13 @@ class DownloadManagerImpl { private ready: boolean = false; private downloadClient: DownloadClient; /** Local cache for thumbnails. Might not be available. */ - private thumbnailCache?: EnteCache; + private thumbnailCache?: BlobCache; /** * Local cache for the files themselves. * * Only available when we're running in the desktop app. */ - private fileCache?: EnteCache; + private fileCache?: BlobCache; private cryptoWorker: Remote; private fileObjectURLPromises = new Map>(); diff --git a/web/apps/photos/src/utils/machineLearning/faceCrop.ts b/web/apps/photos/src/utils/machineLearning/faceCrop.ts index f96e43ce8..9d2c530b3 100644 --- a/web/apps/photos/src/utils/machineLearning/faceCrop.ts +++ b/web/apps/photos/src/utils/machineLearning/faceCrop.ts @@ -1,4 +1,4 @@ -import { openCache } from "@/next/cache"; +import { openCache } from "@/next/blob-cache"; import { BlobOptions } from "types/image"; import { FaceAlignment, diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.ts index 1e57b61f7..2cd0b938f 100644 --- a/web/apps/photos/src/utils/machineLearning/index.ts +++ b/web/apps/photos/src/utils/machineLearning/index.ts @@ -1,4 +1,4 @@ -import { cached } from "@/next/cache"; +import { cached } from "@/next/blob-cache"; import log from "@/next/log"; import { FILE_TYPE } from "constants/file"; import PQueue from "p-queue"; diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts index 3861c64f5..fb0e1c929 100644 --- a/web/packages/accounts/services/user.ts +++ b/web/packages/accounts/services/user.ts @@ -1,4 +1,4 @@ -import { clearCaches } from "@/next/cache"; +import { clearCaches } from "@/next/blob-cache"; import log from "@/next/log"; import { Events, eventBus } from "@ente/shared/events"; import InMemoryStore from "@ente/shared/storage/InMemoryStore"; diff --git a/web/packages/next/cache.ts b/web/packages/next/blob-cache.ts similarity index 89% rename from web/packages/next/cache.ts rename to web/packages/next/blob-cache.ts index 5137150a1..bd1f77bbb 100644 --- a/web/packages/next/cache.ts +++ b/web/packages/next/blob-cache.ts @@ -1,6 +1,6 @@ import isElectron from "is-electron"; -const cacheNames = [ +const blobCacheNames = [ "thumbs", "face-crops", // Desktop app only @@ -8,15 +8,15 @@ const cacheNames = [ ] as const; /** - * Namespaces into which our caches data is divided + * Namespaces into which our blob caches are divided * * Note that namespaces are just arbitrary (but predefined) strings to split the * cached data into "folders", so to speak. * */ -export type CacheName = (typeof cacheNames)[number]; +export type BlobCacheNamespace = (typeof blobCacheNames)[number]; /** - * A namespaced cache. + * A namespaced blob cache. * * This cache is suitable for storing large amounts of data (entire files). * @@ -53,11 +53,11 @@ export type CacheName = (typeof cacheNames)[number]; * * See also: [Note: Increased disk cache for the desktop app]. */ -export interface EnteCache { +export interface BlobCache { /** * Get the data corresponding to {@link key} (if found) from the cache. */ - get: (key: string) => Promise; + get: (key: string) => Promise; match: (key: string) => Promise; /** * Add the given {@link key}-value ({@link data}) pair to the cache. @@ -73,13 +73,15 @@ export interface EnteCache { } /** - * Return the {@link EnteCache} corresponding to the given {@link name}. + * Return the {@link BlobCache} corresponding to the given {@link name}. * * @param name One of the arbitrary but predefined namespaces of type - * {@link CacheName} which group related data and allow us to use the same key - * across namespaces. + * {@link BlobCacheNamespace} which group related data and allow us to use the + * same key across namespaces. */ -export const openCache = async (name: CacheName): Promise => +export const openCache = async ( + name: BlobCacheNamespace, +): Promise => isElectron() ? openOPFSCacheWeb(name) : openWebCache(name); /** @@ -111,8 +113,8 @@ export const openCache = async (name: CacheName): Promise => * - https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob */ -/** An implementation of {@link EnteCache} using Web Cache APIs */ -const openWebCache = async (name: CacheName) => { +/** An implementation of {@link BlobCache} using Web Cache APIs */ +const openWebCache = async (name: BlobCacheNamespace) => { const cache = await caches.open(name); return { get: async (key: string) => { @@ -132,8 +134,8 @@ const openWebCache = async (name: CacheName) => { }; }; -/** An implementation of {@link EnteCache} using OPFS */ -const openOPFSCacheWeb = async (name: CacheName) => { +/** An implementation of {@link BlobCache} using OPFS */ +const openOPFSCacheWeb = async (name: BlobCacheNamespace) => { // While all major browsers support OPFS now, their implementations still // have various quirks. However, we don't need to handle all possible cases // and can just instead use the APIs and guarantees Chromium provides since @@ -186,7 +188,7 @@ const openOPFSCacheWeb = async (name: CacheName) => { }; export async function cached( - cacheName: CacheName, + cacheName: BlobCacheNamespace, id: string, get: () => Promise, ): Promise { @@ -219,7 +221,7 @@ export const clearCaches = async () => isElectron() ? clearOPFSCaches() : clearWebCaches(); export const clearWebCaches = async () => { - await Promise.all(cacheNames.map((name) => caches.delete(name))); + await Promise.all(blobCacheNames.map((name) => caches.delete(name))); }; export const clearOPFSCaches = async () => {