Scaffold the split
This commit is contained in:
parent
41472eb87d
commit
a2a8be3b19
1 changed files with 21 additions and 1 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue