forgot a hashvalue always changes so I can't use that, therefore I created extension on URL for a UniqueIdentifier based of crypto that will always be the same.

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-20 19:28:06 -06:00
parent 887cfd99ea
commit a1214cf38b
2 changed files with 17 additions and 1 deletions

View File

@ -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()
}
}

View File

@ -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) {