【发布时间】:2015-03-15 12:42:50
【问题描述】:
我正在编写一个使用 Parse.com 作为后端的 iOS 应用程序。
在我的PFQueryTableViewController 的- (PFQuery)queryForTable 方法中,我正在从 Parse 检索一组数据,但我无法缓存此查询以支持设备当前离线时的功能。
方法如下:
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey:@"city" equalTo:[[NSUserDefaults standardUserDefaults] objectForKey:@"city"]];
// userMode is active when a user is logged in and is about to edit coins
if (self.userModeActive) {
[query whereKey:self.textKey equalTo:self.user[@"location"]];
}
// dateFilter is active when view is pushed from an event
if (self.dateFilterActive) {
[self createDateRangeForFilter];
[query whereKey:@"date" greaterThan:[[self createDateRangeForFilter] objectAtIndex:0]];
[query whereKey:@"date" lessThan:[[self createDateRangeForFilter] objectAtIndex:1]];
} else {
// Add a negative time interval to take care of coins when it's after midnight
[query whereKey:@"date" greaterThanOrEqualTo:[[NSDate date] dateByAddingTimeInterval:-(60 * 60 * 6)]];
[query orderByAscending:self.dateKey];
}
// locationFilter is active when view is pushed from a location profile
if (self.locationFilterActive) {
[query whereKey:@"location" equalTo:self.locationToFilter];
}
// If no objects are loaded in memory, look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
if ([query hasCachedResult]) {
NSLog(@"hasCache");
} else {
NSLog(@"chache empty");
}
return query;
}
[query hasCachedResults] 在这种情况下总是返回 false。
在另一个类中,我正在执行几乎完全相同的查询(在不同的 Parse-Class 上)并且它会自动缓存。唯一的区别是,这个其他查询包含PFFiles。
这可能是一个愚蠢的问题,但我已经坚持了好几天了。
感谢您的帮助,如果我可以为您提供更多信息,请告诉我。
【问题讨论】:
标签: xcode object caching parse-platform pfquery