This repository has been archived on 2025-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
ios_app/Shared/Services/ImageCacheManager.swift
2025-08-14 19:49:42 +03:00

23 lines
795 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

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.

import UIKit
// Менеджер для кеширования изображений в памяти
class ImageCacheManager {
static let shared = ImageCacheManager()
// NSCache будет хранить UIImage по ключу NSString (URL)
// Он автоматически удаляет объекты при нехватке памяти
private let cache = NSCache<NSString, UIImage>()
private init() {}
// Добавить изображение в кеш
func set(_ image: UIImage, forKey key: String) {
cache.setObject(image, forKey: key as NSString)
}
// Получить изображение из кеша
func get(forKey key: String) -> UIImage? {
return cache.object(forKey: key as NSString)
}
}