From aee2ed60277733de53d6947fc095a958b6c9caf7 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 11 Aug 2021 21:06:30 +0800 Subject: [PATCH] iOS: fix multi context,share same zone storage --- doric-iOS/Pod/Classes/DoricSingleton.h | 1 + doric-iOS/Pod/Classes/DoricSingleton.m | 3 +++ doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/DoricSingleton.h b/doric-iOS/Pod/Classes/DoricSingleton.h index 1addb973..b48dd220 100644 --- a/doric-iOS/Pod/Classes/DoricSingleton.h +++ b/doric-iOS/Pod/Classes/DoricSingleton.h @@ -34,6 +34,7 @@ @property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager; @property(nonatomic, strong) DoricNativeDriver *nativeDriver; @property(nonatomic, strong) DoricContextManager *contextManager; +@property(nonatomic, strong) NSMapTable *storageCaches; + (instancetype)instance; diff --git a/doric-iOS/Pod/Classes/DoricSingleton.m b/doric-iOS/Pod/Classes/DoricSingleton.m index e28616fd..2cca63d0 100644 --- a/doric-iOS/Pod/Classes/DoricSingleton.m +++ b/doric-iOS/Pod/Classes/DoricSingleton.m @@ -34,6 +34,9 @@ - (instancetype)init { _enableRecordSnapshot = NO; _jsLoaderManager = [DoricJSLoaderManager new]; _contextManager = [DoricContextManager new]; + _storageCaches = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsCopyIn + valueOptions:NSPointerFunctionsWeakMemory + capacity:0]; } return self; } diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m index fdf232ef..d9872860 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m @@ -19,6 +19,7 @@ #import "DoricStoragePlugin.h" #import "DoricExtensions.h" +#import "DoricSingleton.h" #if __has_include() @@ -184,8 +185,12 @@ - (DoricCache *)getDiskCache:(NSString *)zone { if (zone) { diskCache = self.cachedMap[zone]; if (!diskCache) { - diskCache = [[DoricCache alloc] initWithName:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone] - rootPath:self.basePath]; + diskCache = [DoricSingleton.instance.storageCaches objectForKey:zone]; + if (!diskCache) { + diskCache = [[DoricCache alloc] initWithName:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone] + rootPath:self.basePath]; + [DoricSingleton.instance.storageCaches setObject:diskCache forKey:zone]; + } self.cachedMap[zone] = diskCache; } } else {