File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import Foundation
15
15
public protocol PersistentCacheProtocol {
16
16
func get( key: Data ) throws -> Data ?
17
17
func put( key: Data , value: Data ) throws
18
+ func delete( key: Data ) throws
18
19
}
19
20
20
21
/// SQLite backed persistent cache.
@@ -63,4 +64,14 @@ public final class SQLiteBackedPersistentCache: PersistentCacheProtocol {
63
64
try writeStmt. step ( )
64
65
try writeStmt. finalize ( )
65
66
}
67
+
68
+ public func delete( key: Data ) throws {
69
+ let deleteStmt = try self . db. prepare ( query: " DELETE FROM TSCCACHE WHERE key == ?; " )
70
+ let bindings : [ SQLite . SQLiteValue ] = [
71
+ . blob( key)
72
+ ]
73
+ try deleteStmt. bind ( bindings)
74
+ try deleteStmt. step ( )
75
+ try deleteStmt. finalize ( )
76
+ }
66
77
}
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ class PersistentCacheTests: XCTestCase {
59
59
try decoder. decode ( Value . self, from: $0)
60
60
}
61
61
XCTAssertEqual ( retVal3, value1)
62
+
63
+ try cache. delete ( key: encoder. encode ( key1) )
64
+
65
+ XCTAssertNil ( try cache. get ( key: encoder. encode ( key1) ) )
66
+ let retVal4 = try cache. get ( key: encoder. encode ( key2) ) . map {
67
+ try decoder. decode ( Value . self, from: $0)
68
+ }
69
+ XCTAssertEqual ( retVal4, value2)
62
70
}
63
71
}
64
72
}
You can’t perform that action at this time.
0 commit comments