39 lines
853 B
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// DatabaseID.swift
// NetNewsWire
//
// Created by Brent Simmons on 7/15/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import FoundationExtras
class DatabaseIDCache: @unchecked Sendable {
static let shared = DatabaseIDCache()
private var databaseIDCache = [String: String]()
private let databaseIDCacheLock = NSLock()
/// Generates or retrieves from cache  a database-suitable ID based on a String.
func databaseIDWithString(_ s: String) -> String {
databaseIDCacheLock.lock()
defer {
databaseIDCacheLock.unlock()
}
if let identifier = databaseIDCache[s] {
return identifier
}
// MD5 works because:
// * Its fast
// * Collisions arent going to happen with feed data
let identifier = s.md5String
databaseIDCache[s] = identifier
return identifier
}
}