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;
- (DoricAsyncResult <NSData *> *)fetchRaw;
- (DoricAsyncResult <NSData *> *)fetch;
@end

View File

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

View File

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