feat:iOS DoricResult add fetch cache

This commit is contained in:
pengfei.zhou 2021-11-19 10:26:26 +08:00 committed by osborn
parent 7978900a4f
commit 6ecfc307bf
3 changed files with 15 additions and 1 deletions

View File

@ -29,4 +29,6 @@
- (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier; - (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier;
- (DoricAsyncResult <NSData *> *)fetchRaw; - (DoricAsyncResult <NSData *> *)fetchRaw;
- (DoricAsyncResult <NSData *> *)fetch;
@end @end

View File

@ -19,6 +19,10 @@
#import "DoricResource.h" #import "DoricResource.h"
@interface DoricResource ()
@property(nonatomic, strong) DoricAsyncResult<NSData *> *result;
@end
@implementation DoricResource @implementation DoricResource
- (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier { - (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier {
if (self = [super init]) { if (self = [super init]) {
@ -27,7 +31,15 @@ - (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)i
} }
return self; return self;
} }
- (DoricAsyncResult<NSData *> *)fetchRaw { - (DoricAsyncResult<NSData *> *)fetchRaw {
return nil; return nil;
} }
- (DoricAsyncResult <NSData *> *)fetch {
if (!self.result) {
self.result = [self fetchRaw];
}
return self.result;
}
@end @end

View File

@ -238,7 +238,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
if ([@"image" isEqualToString:name]) { if ([@"image" isEqualToString:name]) {
DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager
load:prop load:prop
withContext:self.doricContext] fetchRaw]; withContext:self.doricContext] fetch];
[asyncResult setResultCallback:^(NSData *imageData) { [asyncResult setResultCallback:^(NSData *imageData) {
[self.doricContext dispatchToMainQueue:^{ [self.doricContext dispatchToMainQueue:^{
#if DORIC_USE_YYWEBIMAGE #if DORIC_USE_YYWEBIMAGE