Skip to content

Commit d335421

Browse files
committed
所有 Get 请求,增加缓存机制
1 parent c9afb65 commit d335421

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Coding_iOS/Util/Manager/CodingNetAPIClient.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,28 @@ - (void)requestJsonDataWithPath:(NSString *)aPath
6666
//发起请求
6767
switch (method) {
6868
case Get:{
69+
//所有 Get 请求,增加缓存机制
70+
NSMutableString *localPath = [aPath mutableCopy];
71+
if (params) {
72+
[localPath appendString:params.description];
73+
}
6974
[self GET:aPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
7075
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, responseObject);
7176
id error = [self handleResponse:responseObject autoShowError:autoShowError];
7277
if (error) {
73-
block(nil, error);
78+
responseObject = [NSObject loadResponseWithPath:localPath];
79+
block(responseObject, error);
7480
}else{
81+
if ([responseObject isKindOfClass:[NSDictionary class]]) {
82+
[NSObject saveResponseData:responseObject toPath:localPath];
83+
}
7584
block(responseObject, nil);
7685
}
7786
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
7887
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, error);
7988
!autoShowError || [self showError:error];
80-
block(nil, error);
89+
id responseObject = [NSObject loadResponseWithPath:localPath];
90+
block(responseObject, error);
8191
}];
8292
break;}
8393
case Post:{

0 commit comments

Comments
 (0)