feat:storage demo success to run

This commit is contained in:
pengfei.zhou
2019-11-22 13:19:54 +08:00
parent af53fd9c75
commit c4d64ff74a
4 changed files with 76 additions and 5 deletions

View File

@@ -20,17 +20,26 @@
#import "DoricStoragePlugin.h"
#import "YYDiskCache.h"
static NSString *doric_prefix = @"pref_doric";
static NSString *doric_prefix = @"pref";
@interface DoricStoragePlugin ()
@property(atomic, strong) NSMutableDictionary <NSString *, YYDiskCache *> *cachedMap;
@property(nonatomic, strong) YYDiskCache *defaultCache;
@property(nonatomic, copy) NSString *basePath;
@end
@implementation DoricStoragePlugin
- (instancetype)initWithContext:(DoricContext *)doricContext {
if (self = [super initWithContext:doricContext]) {
_basePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
stringByAppendingPathComponent:@"doric"];
}
return self;
}
- (YYDiskCache *)defaultCache {
if (!_defaultCache) {
_defaultCache = [[YYDiskCache alloc] initWithPath:doric_prefix];
_defaultCache = [[YYDiskCache alloc] initWithPath:[self.basePath stringByAppendingPathComponent:doric_prefix]];
}
return _defaultCache;
}
@@ -40,7 +49,8 @@ - (YYDiskCache *)getDiskCache:(NSString *)zone {
if (zone) {
diskCache = self.cachedMap[zone];
if (!diskCache) {
diskCache = [[YYDiskCache alloc] initWithPath:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone]];
diskCache = [[YYDiskCache alloc] initWithPath:[self.basePath
stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone]]];
self.cachedMap[zone] = diskCache;
}
} else {