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 {