|
@@ -37,6 +37,9 @@ |
|
@@ -37,6 +37,9 @@ |
37
|
{
|
37
|
{
|
38
|
[db executeUpdate:@"CREATE TABLE IF NOT EXISTS ZCACHE (ztileHash INTEGER PRIMARY KEY, zlastUsed DOUBLE, zdata BLOB)"];
|
38
|
[db executeUpdate:@"CREATE TABLE IF NOT EXISTS ZCACHE (ztileHash INTEGER PRIMARY KEY, zlastUsed DOUBLE, zdata BLOB)"];
|
39
|
[db executeUpdate:@"CREATE INDEX IF NOT EXISTS zlastUsedIndex ON ZCACHE(zLastUsed)"];
|
39
|
[db executeUpdate:@"CREATE INDEX IF NOT EXISTS zlastUsedIndex ON ZCACHE(zLastUsed)"];
|
|
|
40
|
+ // adding more than once does not seem to break anything
|
|
|
41
|
+ [db executeUpdate:@"ALTER TABLE ZCACHE ADD COLUMN zInserted DOUBLE"];
|
|
|
42
|
+ [db executeUpdate:@"CREATE INDEX IF NOT EXISTS zInsertedIndex ON ZCACHE(zInserted)"];
|
40
|
}
|
43
|
}
|
41
|
|
44
|
|
42
|
-(id) initWithDatabase: (NSString*)path
|
45
|
-(id) initWithDatabase: (NSString*)path
|
|
@@ -123,6 +126,27 @@ |
|
@@ -123,6 +126,27 @@ |
123
|
|
126
|
|
124
|
}
|
127
|
}
|
125
|
|
128
|
|
|
|
129
|
+-(void) purgeTilesFromBefore: (NSDate*) date;
|
|
|
130
|
+{
|
|
|
131
|
+ NSUInteger count = 0;
|
|
|
132
|
+ FMResultSet *results = [db executeQuery:@"SELECT COUNT(ztileHash) FROM ZCACHE WHERE zInserted < ?", date];
|
|
|
133
|
+ if ([results next]) {
|
|
|
134
|
+ count = [results intForColumnIndex:0];
|
|
|
135
|
+ RMLog(@"Will purge %i tile(s) from before %@", count, date);
|
|
|
136
|
+ }
|
|
|
137
|
+ [results close];
|
|
|
138
|
+
|
|
|
139
|
+ if (count == 0) {
|
|
|
140
|
+ return;
|
|
|
141
|
+ }
|
|
|
142
|
+
|
|
|
143
|
+ BOOL result = [db executeUpdate: @"DELETE FROM ZCACHE WHERE zInserted < ?",
|
|
|
144
|
+ date];
|
|
|
145
|
+ if (result == NO) {
|
|
|
146
|
+ RMLog(@"Error purging cache");
|
|
|
147
|
+ }
|
|
|
148
|
+}
|
|
|
149
|
+
|
126
|
-(void) removeAllCachedImages
|
150
|
-(void) removeAllCachedImages
|
127
|
{
|
151
|
{
|
128
|
BOOL result = [db executeUpdate: @"DELETE FROM ZCACHE"];
|
152
|
BOOL result = [db executeUpdate: @"DELETE FROM ZCACHE"];
|
|
@@ -145,8 +169,8 @@ |
|
@@ -145,8 +169,8 @@ |
145
|
{
|
169
|
{
|
146
|
// Fixme
|
170
|
// Fixme
|
147
|
// RMLog(@"addData\t%d", tileHash);
|
171
|
// RMLog(@"addData\t%d", tileHash);
|
148
|
- BOOL result = [db executeUpdate:@"INSERT OR IGNORE INTO ZCACHE (ztileHash, zlastUsed, zdata) VALUES (?, ?, ?)",
|
|
|
149
|
- [NSNumber numberWithUnsignedLongLong:tileHash], date, data];
|
172
|
+ BOOL result = [db executeUpdate:@"INSERT OR REPLACE INTO ZCACHE (ztileHash, zlastUsed, zInserted, zdata) VALUES (?, ?, ?, ?)",
|
|
|
173
|
+ [NSNumber numberWithUnsignedLongLong:tileHash], date, [NSDate date], data];
|
150
|
if (result == NO)
|
174
|
if (result == NO)
|
151
|
{
|
175
|
{
|
152
|
RMLog(@"Error occured adding data");
|
176
|
RMLog(@"Error occured adding data");
|