     
     public init(version: Version? = nil) throws {
         db = try Connection()
+        i2tcache = LRUCache(capacity: 1024)
+        t2icache = LRUCache(capacity: 1024)
         try initializeTables()
         if let v = version {
             try db.run(sysTable.update(versionColumn <- Int64(v)))

            let value = row[termValueColumn]
            switch type {
            case .iri:
                return Term(iri: value)
            case .blank:
                return Term(value: value, type: .blank)
            case .literal:
                guard let datatypeID = row[termDatatypeColumn] else {
                    return nil

        guard let dbh = try? db.prepare(query) else {
            return AnyIterator { return nil }
        }
        let results = dbh.lazy.compactMap { (row) -> TermResult? in
            var bindings = [String: Term]()
            for (name, cols) in mapping {
                if cols.count == 1 {
                    let col = cols.first!
                    let id = row[col]
                    guard let t = self.term(for: id) else { return nil }
                    bindings[name] = t
                } else {
                    let ids = cols.map { row[$0] }
                    let terms = ids.compactMap { self.term(for: $0) }
                    guard terms.count == cols.count else { return nil }
                    if let t = terms.first {
                        guard terms.allSatisfy({ t == $0 }) else {
