yattee/Model/Cache/CacheModel.swift

31 lines
861 B
Swift
Raw Normal View History

2022-12-10 02:01:59 +00:00
import Cache
2022-11-10 17:11:28 +00:00
import Foundation
2022-12-10 00:23:13 +00:00
import Logging
2022-12-10 02:01:59 +00:00
import SwiftyJSON
2022-11-10 17:11:28 +00:00
struct CacheModel {
static var shared = CacheModel()
2022-12-10 02:01:59 +00:00
static let jsonToDataTransformer: (JSON) -> Data = { try! $0.rawData() }
static let jsonFromDataTransformer: (Data) -> JSON = { try! JSON(data: $0) }
static let jsonTransformer = Transformer(toData: jsonToDataTransformer, fromData: jsonFromDataTransformer)
func clear() {
FeedCacheModel.shared.clear()
VideosCacheModel.shared.clear()
}
var totalSize: Int {
(FeedCacheModel.shared.storage.totalDiskStorageSize ?? 0) +
(VideosCacheModel.shared.storage.totalDiskStorageSize ?? 0)
}
var totalSizeFormatted: String {
totalSizeFormatter.string(fromByteCount: Int64(totalSize))
}
private var totalSizeFormatter: ByteCountFormatter {
.init()
}
2022-11-10 17:11:28 +00:00
}