Permalink
Browse files

fixes #138: add more cache API & detect cache before trying async loads

  • Loading branch information...
1 parent 84962c2 commit 1c249764a913a19d64de817074c656a39abf492b @incanus incanus committed Nov 20, 2012
@@ -62,6 +62,9 @@
* @param theCapacity The number of tiles to allow to accumulate in the database before purging begins. */
- (void)setCapacity:(NSUInteger)theCapacity;
+/** The capacity, in number of tiles, that the database cache can hold. */
+@property (nonatomic, readonly, assign) NSUInteger capacity;
+
/** Set the minimum number of tiles to purge when clearing space in the cache.
* @param thePurgeMinimum The number of tiles to delete at the time the cache is purged. */
- (void)setMinimalPurge:(NSUInteger)thePurgeMinimum;
@@ -164,6 +164,11 @@ - (void)setCapacity:(NSUInteger)theCapacity
_capacity = theCapacity;
}
+- (NSUInteger)capacity
+{
+ return _capacity;
+}
+
- (void)setMinimalPurge:(NSUInteger)theMinimalPurge
{
_minimalPurge = theMinimalPurge;
@@ -15,6 +15,7 @@
#import "RMMBTilesSource.h"
#import "RMDBMapSource.h"
#import "RMAbstractWebMapSource.h"
+#import "RMDatabaseCache.h"
#define IS_VALID_TILE_IMAGE(image) (image != nil && [image isKindOfClass:[UIImage class]])
@@ -132,7 +133,13 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context
if (zoom >= _tileSource.minZoom && zoom <= _tileSource.maxZoom)
{
- if ( ! [_tileSource isKindOfClass:[RMAbstractWebMapSource class]])
+ RMDatabaseCache *databaseCache = nil;
+
+ for (RMTileCache *componentCache in _mapView.tileCache.tileCaches)
+ if ([componentCache isKindOfClass:[RMDatabaseCache class]])
+ databaseCache = (RMDatabaseCache *)componentCache;
+
+ if ( ! [_tileSource isKindOfClass:[RMAbstractWebMapSource class]] || ! databaseCache || ! databaseCache.capacity)
{
// for non-web tiles, query the source directly since trivial blocking
//
@@ -39,6 +39,11 @@
* @return An initialized memory cache object or `nil` if the object couldn't be created. */
- (id)initWithCapacity:(NSUInteger)aCapacity;
+/** @name Cache Capacity */
+
+/** The capacity, in number of tiles, that the memory cache can hold. */
+@property (nonatomic, readonly, assign) NSUInteger capacity;
+
/** @name Making Space in the Cache */
/** Remove the least-recently used image from the cache if the cache is at or over capacity. This removes a single image from the cache. */
@@ -120,6 +120,11 @@ - (UIImage *)cachedImage:(RMTile)tile withCacheKey:(NSString *)aCacheKey
return [cachedObject cachedObject];
}
+- (NSUInteger)capacity
+{
+ return _memoryCacheCapacity;
+}
+
/// Remove the least-recently used image from cache, if cache is at or over capacity. Removes only 1 image.
- (void)makeSpaceInCache
{
@@ -101,6 +101,9 @@ typedef enum : short {
- (void)addCache:(id <RMTileCache>)cache;
- (void)insertCache:(id <RMTileCache>)cache atIndex:(NSUInteger)index;
+/** The list of caches managed by a cache manager. This could include memory-based, disk-based, or other types of caches. */
+@property (nonatomic, readonly, retain) NSArray *tileCaches;
+
- (void)didReceiveMemoryWarning;
@end
@@ -138,6 +138,11 @@ - (void)insertCache:(id <RMTileCache>)cache atIndex:(NSUInteger)index
});
}
+- (NSArray *)tileCaches
+{
+ return [NSArray arrayWithArray:_tileCaches];
+}
+
+ (NSNumber *)tileHash:(RMTile)tile
{
return [NSNumber numberWithUnsignedLongLong:RMTileKey(tile)];

0 comments on commit 1c24976

Please sign in to comment.