Skip to content

armgit / ente

Public Imported from GitHub
0

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

Scaffold the split

Manav Rathia2a8be3b1995
diff --git a/web/packages/shared/storage/cache.ts b/web/packages/shared/storage/cache.ts
index 48d18ef73b..63ab5c404a 100644
--- a/web/packages/shared/storage/cache.ts
+++ b/web/packages/shared/storage/cache.ts
@@ -76,7 +76,27 @@ export interface EnteCache {
* {@link CacheName} which group related data and allow us to use the same key
* across namespaces.
*/
-const openCache = async (name: CacheName) => {
+const openCache = async (name: CacheName) =>
+ globalThis.electron ? openWebCache(name) : openOPFSCacheWeb(name);
+
+/** An implementation of {@link EnteCache} using Web Cache APIs */
+const openWebCache = async (name: CacheName) => {
+ const cache = await caches.open(name);
+ return {
+ match: (key) => {
+ return cache.match(key);
+ },
+ put: (key: string, data: Response) => {
+ return cache.put(key, data);
+ },
+ delete: (key: string) => {
+ return cache.delete(key);
+ },
+ };
+};
+
+/** An implementation of {@link EnteCache} using OPFS */
+const openOPFSCacheWeb = async (name: CacheName) => {
const cache = await caches.open(name);
return {
match: (key) => {