iOS: fix multi context,share same zone storage

This commit is contained in:
pengfei.zhou 2021-08-11 21:06:30 +08:00 committed by osborn
parent 33c681031d
commit aee2ed6027
3 changed files with 11 additions and 2 deletions

View File

@ -34,6 +34,7 @@
@property(nonatomic, strong) DoricJSLoaderManager *jsLoaderManager;
@property(nonatomic, strong) DoricNativeDriver *nativeDriver;
@property(nonatomic, strong) DoricContextManager *contextManager;
@property(nonatomic, strong) NSMapTable<NSString *, id> *storageCaches;
+ (instancetype)instance;

View File

@ -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;
}

View File

@ -19,6 +19,7 @@
#import "DoricStoragePlugin.h"
#import "DoricExtensions.h"
#import "DoricSingleton.h"
#if __has_include(<PINCache/PINCache.h>)
@ -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 {