【发布时间】:2013-06-05 23:59:16
【问题描述】:
我使用 Parse.com
构建了一个 iOS 应用程序我想先从缓存和然后从网络
检索数据为此,我使用了 kPFCachePolicyCacheThenNetwork 缓存策略,这符合我的要求。
PFQuery *employesquery = [PFQuery queryWithClassName:@"employesTable"];
[employesquery whereKey:@"UserID" equalTo:[PFUser currentUser]];
[employesquery includeKey:@"empID"];
[employesquery includeKey:@"empID.user"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
//APPLIES CACHE... ********
employesquery.cachePolicy = kPFCachePolicyCacheThenNetwork;
[employesquery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[hud hide:YES];
NSMutableArray *empData = [[NSMutableArray alloc] init];
for (PFObject *object in objects)
{
//Getting Data For Item
PFObject *employeeObject = [object objectForKey:@"empID"];
[empData addObject:employeeObject];
}
[self fetchEmployeeData:empData];
}];
但是使用这个每个数据检索两次,可重复的数据。
如何避免这种重复数据,
一旦从网络获取数据,之前显示的数据(使用缓存)就会被清除/隐藏。
我试过[PFQuery clearAllCachedResults];
清空所有缓存,使得下一次迭代的缓存中没有数据。
【问题讨论】:
标签: iphone ios objective-c caching parse-platform