o Offline database cache may have different capacity values for iPhone and iPad
Showing
1 changed file
with
41 additions
and
38 deletions
@@ -183,50 +183,53 @@ | @@ -183,50 +183,53 @@ | ||
183 | 183 | ||
184 | - (id <RMTileCache>)databaseCacheWithConfig:(NSDictionary *)cfg | 184 | - (id <RMTileCache>)databaseCacheWithConfig:(NSDictionary *)cfg |
185 | { | 185 | { |
186 | - BOOL useCacheDir = NO; | ||
187 | - RMCachePurgeStrategy strategy = RMCachePurgeStrategyFIFO; | ||
188 | - | ||
189 | - NSUInteger capacity = 1000; | ||
190 | - NSUInteger minimalPurge = capacity / 10; | ||
191 | - | ||
192 | - NSNumber *capacityNumber = [cfg objectForKey:@"capacity"]; | ||
193 | - if (capacityNumber != nil) { | ||
194 | - NSInteger value = [capacityNumber intValue]; | ||
195 | - | ||
196 | - // 0 is valid: it means no capacity limit | ||
197 | - if (value >= 0) { | ||
198 | - capacity = value; | ||
199 | - minimalPurge = MAX(1,capacity / 10); | ||
200 | - } else | ||
201 | - RMLog(@"illegal value for capacity: %d", value); | ||
202 | - } | 186 | + BOOL useCacheDir = NO; |
187 | + RMCachePurgeStrategy strategy = RMCachePurgeStrategyFIFO; | ||
203 | 188 | ||
204 | - NSString *strategyStr = [cfg objectForKey:@"strategy"]; | ||
205 | - if (strategyStr != nil) { | ||
206 | - if ([strategyStr caseInsensitiveCompare:@"FIFO"] == NSOrderedSame) strategy = RMCachePurgeStrategyFIFO; | ||
207 | - if ([strategyStr caseInsensitiveCompare:@"LRU"] == NSOrderedSame) strategy = RMCachePurgeStrategyLRU; | ||
208 | - } | 189 | + NSUInteger capacity = 1000; |
190 | + NSUInteger minimalPurge = capacity / 10; | ||
191 | + | ||
192 | + NSNumber *capacityNumber = [cfg objectForKey:@"capacity"]; | ||
193 | + if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad && [cfg objectForKey:@"capacity-ipad"]) | ||
194 | + capacityNumber = [cfg objectForKey:@"capacity-ipad"]; | ||
195 | + | ||
196 | + if (capacityNumber != nil) { | ||
197 | + NSInteger value = [capacityNumber intValue]; | ||
198 | + | ||
199 | + // 0 is valid: it means no capacity limit | ||
200 | + if (value >= 0) { | ||
201 | + capacity = value; | ||
202 | + minimalPurge = MAX(1,capacity / 10); | ||
203 | + } else | ||
204 | + RMLog(@"illegal value for capacity: %d", value); | ||
205 | + } | ||
209 | 206 | ||
210 | - NSNumber *useCacheDirNumber = [cfg objectForKey:@"useCachesDirectory"]; | ||
211 | - if (useCacheDirNumber != nil) | 207 | + NSString *strategyStr = [cfg objectForKey:@"strategy"]; |
208 | + if (strategyStr != nil) { | ||
209 | + if ([strategyStr caseInsensitiveCompare:@"FIFO"] == NSOrderedSame) strategy = RMCachePurgeStrategyFIFO; | ||
210 | + if ([strategyStr caseInsensitiveCompare:@"LRU"] == NSOrderedSame) strategy = RMCachePurgeStrategyLRU; | ||
211 | + } | ||
212 | + | ||
213 | + NSNumber *useCacheDirNumber = [cfg objectForKey:@"useCachesDirectory"]; | ||
214 | + if (useCacheDirNumber != nil) | ||
212 | useCacheDir = [useCacheDirNumber boolValue]; | 215 | useCacheDir = [useCacheDirNumber boolValue]; |
213 | 216 | ||
214 | - NSNumber *minimalPurgeNumber = [cfg objectForKey:@"minimalPurge"]; | ||
215 | - if (minimalPurgeNumber != nil && capacity != 0) { | ||
216 | - NSUInteger value = [minimalPurgeNumber unsignedIntValue]; | ||
217 | - if (value > 0 && value<=capacity) | ||
218 | - minimalPurge = value; | ||
219 | - else { | ||
220 | - RMLog(@"minimalPurge must be at least one and at most the cache capacity"); | ||
221 | - } | ||
222 | - } | 217 | + NSNumber *minimalPurgeNumber = [cfg objectForKey:@"minimalPurge"]; |
218 | + if (minimalPurgeNumber != nil && capacity != 0) { | ||
219 | + NSUInteger value = [minimalPurgeNumber unsignedIntValue]; | ||
220 | + if (value > 0 && value<=capacity) { | ||
221 | + minimalPurge = value; | ||
222 | + } else { | ||
223 | + RMLog(@"minimalPurge must be at least one and at most the cache capacity"); | ||
224 | + } | ||
225 | + } | ||
223 | 226 | ||
224 | - RMDatabaseCache *dbCache = [[[RMDatabaseCache alloc] initUsingCacheDir:useCacheDir] autorelease]; | ||
225 | - [dbCache setCapacity:capacity]; | ||
226 | - [dbCache setPurgeStrategy:strategy]; | ||
227 | - [dbCache setMinimalPurge:minimalPurge]; | 227 | + RMDatabaseCache *dbCache = [[[RMDatabaseCache alloc] initUsingCacheDir:useCacheDir] autorelease]; |
228 | + [dbCache setCapacity:capacity]; | ||
229 | + [dbCache setPurgeStrategy:strategy]; | ||
230 | + [dbCache setMinimalPurge:minimalPurge]; | ||
228 | 231 | ||
229 | - return dbCache; | 232 | + return dbCache; |
230 | } | 233 | } |
231 | 234 | ||
232 | @end | 235 | @end |
-
Please register or login to post a comment