RMDatabaseCache.m
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// RMDatabaseCache.m
// RouteMe
//
// Created by Joseph Gentle on 19/09/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMDatabaseCache.h"
#import "RMTileCacheDAO.h"
#import "RMTileImage.h"
#import "RMTile.h"
//static BOOL installed = NO;
@implementation RMDatabaseCache
-(id) init
{
if (![super init])
return nil;
// NSLog(@"%d items in DB", [[DAO sharedManager] count]);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(addImageData:)
name:RMMapImageLoadedNotification
object:nil];
return self;
}
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
-(void) addImageData: (NSNotification *)notification
{
// NSLog(@"AddImageData");
NSData *data = [[notification userInfo] objectForKey:@"data"];
RMTileImage *image = (RMTileImage*)[notification object];
[[RMTileCacheDAO sharedManager] addData:data LastUsed:[image lastUsedTime] ForTile:RMTileHash([image tile])];
// NSLog(@"%d items in DB", [[DAO sharedManager] count]);
}
-(RMTileImage*) cachedImage:(RMTile)tile
{
// NSLog(@"Looking for cached image in DB");
NSData *data = [[RMTileCacheDAO sharedManager] dataForTile:RMTileHash(tile)];
if (data == nil)
return nil;
RMTileImage *image = [RMTileImage imageWithTile:tile FromData:data];
// NSLog(@"DB cache hit for tile %d %d %d", tile.x, tile.y, tile.zoom);
return image;
}
/*
+(void) install
{
if (installed)
return;
RMDatabaseCache *dbCache = [[RMDatabaseCache alloc] init];
[[RMTileCache sharedCache] addCache:dbCache];
[dbCache release];
installed = YES;
}*/
@end