metatext-app-ios-iphone-ipad/Caches/ImageCacheConfiguration.swift

37 lines
1.4 KiB
Swift
Raw Normal View History

2021-01-30 02:14:22 +01:00
// Copyright © 2021 Metabolist. All rights reserved.
import Foundation
2021-02-23 00:59:33 +01:00
import SDWebImage
2021-01-30 02:14:22 +01:00
import ServiceLayer
struct ImageCacheConfiguration {
private let environment: AppEnvironment
init(environment: AppEnvironment) {
self.environment = environment
}
}
extension ImageCacheConfiguration {
func configure() throws {
2021-02-23 00:59:33 +01:00
SDImageCache.defaultDiskCacheDirectory = Self.imageCacheDirectoryURL?.path
ImageDiskCache.service = try ImageSerializationService(environment: environment)
SDImageCacheConfig.default.diskCacheClass = ImageDiskCache.self
if let legacyImageCacheDirectoryURL = Self.legacyImageCacheDirectoryURL,
FileManager.default.fileExists(atPath: legacyImageCacheDirectoryURL.path) {
try? FileManager.default.removeItem(at: legacyImageCacheDirectoryURL)
}
2021-01-30 02:14:22 +01:00
}
}
private extension ImageCacheConfiguration {
2021-02-23 00:59:33 +01:00
static let cachesDirectoryURL = FileManager.default.containerURL(
2021-01-30 02:14:22 +01:00
forSecurityApplicationGroupIdentifier: AppEnvironment.appGroup)?
.appendingPathComponent("Library")
.appendingPathComponent("Caches")
2021-02-23 00:59:33 +01:00
static let imageCacheDirectoryURL = cachesDirectoryURL?.appendingPathComponent("com.metabolist.metatext.images")
static let legacyImageCacheDirectoryURL =
cachesDirectoryURL?.appendingPathComponent("com.onevcat.Kingfisher.ImageCache.Images")
2021-01-30 02:14:22 +01:00
}