 
     fileprivate mutating func get(_ file: File) -> T {
         let key = file.cacheKey
-        if let value = values[key] {
-            return value
-        }
+        lock.lock()
+        if let cachedValue = values[key] {
+            lock.unlock()
+            return cachedValue
+        }
+        lock.unlock()
         let value = factory(file)
-        values[key] = value
+        set(key: key, value: value)
         return value
     }
 
     fileprivate mutating func invalidate(_ file: File) {
         if let key = file.path {
-            values.removeValue(forKey: key)
+            doLocked { values.removeValue(forKey: key) }
         }
     }
 
     fileprivate mutating func clear() {
-        values.removeAll(keepingCapacity: false)
+        doLocked { values.removeAll(keepingCapacity: false) }
+    }
+
+    fileprivate mutating func set(key: String, value: T) {
+        doLocked { values[key] = value }
+    }
+
+    fileprivate mutating func unset(key: String) {
+        doLocked { values.removeValue(forKey: key) }
+    }
+
+    private func doLocked(block: () -> Void) {
+        lock.lock()
+        block()
+        lock.unlock()
     }
 }
 

    }

    internal static var allDeclarationsByType: [String: [String]] {
        if !queueForRebuild.isEmpty {
            rebuildAllDeclarationsByType()
        }
        return _allDeclarationsByType
    }
}

private func rebuildAllDeclarationsByType() {
    let allDeclarationsByType = queueForRebuild.flatMap { structure -> (String, [String])? in
        guard let firstSubstructureDict = structure.dictionary.substructure.first,
            let name = firstSubstructureDict["key.name"] as? String,
            let kind = (firstSubstructureDict["key.kind"] as? String)
                .flatMap(SwiftDeclarationKind.init),
            kind == .protocol,
            case let substructure = firstSubstructureDict.substructure,
            !substructure.isEmpty else {
                return nil
        }
        return (name, substructure.flatMap({ $0["key.name"] as? String }))
    }
    allDeclarationsByType.forEach { _allDeclarationsByType[$0.0] = $0.1 }
    queueForRebuild = []
}

        }
        set {
            if newValue {
                responseCache.set(key: cacheKey, value: nil)
            } else {
                responseCache.unset(key: cacheKey)
            }
        }
    }
