Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/ApolloSQLite/SQLiteNormalizedCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public final class SQLiteNormalizedCache {
try self.createTableIfNeeded()
}

///
/// Initializer that takes the Connection to use
/// - Parameters:
/// - db: The database Connection to use
/// - shouldVacuumOnClear: If the database should also be `VACCUM`ed on clear to remove all traces of info. Defaults to `false` since this involves a performance hit, but this should be used if you are storing any Personally Identifiable Information in the cache.
/// - Throws: Any errors attempting to access the database
public init(db: Connection, shouldVacuumOnClear: Bool = false) throws {
self.shouldVacuumOnClear = shouldVacuumOnClear
self.db = db
try self.createTableIfNeeded()
}

private func recordCacheKey(forFieldCacheKey fieldCacheKey: CacheKey) -> CacheKey {
let components = fieldCacheKey.components(separatedBy: ".")
var updatedComponents = [String]()
Expand Down
5 changes: 5 additions & 0 deletions Tests/ApolloSQLiteTests/CachePersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import XCTest
import ApolloTestSupport
import ApolloSQLiteTestSupport
import StarWarsAPI
import SQLite

class CachePersistenceTests: XCTestCase {

Expand Down Expand Up @@ -59,6 +60,10 @@ class CachePersistenceTests: XCTestCase {
}
}

func testPassInConnectionDoesNotThrow() {
XCTAssertNoThrow(try SQLiteNormalizedCache(db: Connection()))
}

func testClearCache() {
let query = HeroNameQuery()
let sqliteFileURL = SQLiteTestCacheProvider.temporarySQLiteFileURL()
Expand Down