Skip to content

armgit / ente

Public Imported from GitHub
0

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

Inline the factory

Manav Rathic83dc87d5dc0
diff --git a/web/packages/shared/storage/cache.ts b/web/packages/shared/storage/cache.ts
index be135c1b92..ba26019b94 100644
--- a/web/packages/shared/storage/cache.ts
+++ b/web/packages/shared/storage/cache.ts
@@ -8,10 +8,6 @@ const cacheNames = [
/** Namespaces into which our caches data is divided */
export type CacheName = (typeof cacheNames)[number];
-interface LimitedCacheStorage {
- open: (cacheName: string) => Promise<LimitedCache>;
-}
-
export interface LimitedCache {
match: (
key: string,
@@ -21,34 +17,22 @@ export interface LimitedCache {
delete: (key: string) => Promise<boolean>;
}
-class cacheStorageFactory {
- getCacheStorage(): LimitedCacheStorage {
- return {
- async open(cacheName) {
- const cache = await caches.open(cacheName);
- return {
- match: (key) => {
- // options are not supported in the browser
- return cache.match(key);
- },
- put: cache.put.bind(cache),
- delete: cache.delete.bind(cache),
- };
- },
- };
- }
-}
-
-export const CacheStorageFactory = new cacheStorageFactory();
-
-async function openCache(cacheName: string) {
- return await CacheStorageFactory.getCacheStorage().open(cacheName);
-}
+const openCache = async (name: CacheName) => {
+ const cache = await caches.open(name);
+ return {
+ match: (key) => {
+ // options are not supported in the browser
+ return cache.match(key);
+ },
+ put: cache.put.bind(cache),
+ delete: cache.delete.bind(cache),
+ };
+};
export const CacheStorageService = { open: openCache };
export async function cached(
- cacheName: string,
+ cacheName: CacheName,
id: string,
get: () => Promise<Blob>,
): Promise<Blob> {