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:
parent
887cfd99ea
commit
a1214cf38b
16
EmployeeDirectory/Extensions/URL.swift
Normal file
16
EmployeeDirectory/Extensions/URL.swift
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,7 +20,7 @@ public class ImageCacheService {
|
|||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
public func loadImage(from url: URL) async -> UIImage? {
|
public func loadImage(from url: URL) async -> UIImage? {
|
||||||
let uniqueKey = String(url.absoluteString.hashValue)
|
let uniqueKey = url.uniqueIdentifier
|
||||||
let cacheKey = uniqueKey as NSString
|
let cacheKey = uniqueKey as NSString
|
||||||
|
|
||||||
if let cachedImage = memoryCache.object(forKey: cacheKey) {
|
if let cachedImage = memoryCache.object(forKey: cacheKey) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user