diff --git a/EmployeeDirectory/Extensions/URL.swift b/EmployeeDirectory/Extensions/URL.swift new file mode 100644 index 0000000..e146d27 --- /dev/null +++ b/EmployeeDirectory/Extensions/URL.swift @@ -0,0 +1,16 @@ +// +// URL.swift +// EmployeeDirectory +// +// Created by Matt Bruce on 1/20/25. +// +import Foundation +import CryptoKit + +extension URL { + internal var uniqueIdentifier: String { + let data = Data(absoluteString.utf8) + let hash = SHA256.hash(data: data) + return hash.compactMap { String(format: "%02x", $0) }.joined() + } +} diff --git a/EmployeeDirectory/Services/ImageCacheService.swift b/EmployeeDirectory/Services/ImageCacheService.swift index b28b3c3..ba45f2a 100644 --- a/EmployeeDirectory/Services/ImageCacheService.swift +++ b/EmployeeDirectory/Services/ImageCacheService.swift @@ -20,7 +20,7 @@ public class ImageCacheService { public init() {} public func loadImage(from url: URL) async -> UIImage? { - let uniqueKey = String(url.absoluteString.hashValue) + let uniqueKey = url.uniqueIdentifier let cacheKey = uniqueKey as NSString if let cachedImage = memoryCache.object(forKey: cacheKey) {