1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Model/Cache/CacheModel.swift

49 lines
1.4 KiB
Swift
Raw Normal View History

2022-12-10 07:31:59 +05:30
import Cache
2022-11-10 22:41:28 +05:30
import Foundation
2022-12-10 05:53:13 +05:30
import Logging
2022-12-10 07:31:59 +05:30
import SwiftyJSON
2022-11-10 22:41:28 +05:30
struct CacheModel {
static var shared = CacheModel()
2022-12-10 07:31:59 +05:30
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()
2022-12-11 22:34:39 +05:30
PlaylistsCacheModel.shared.clear()
2022-12-10 07:31:59 +05:30
}
var totalSize: Int {
(FeedCacheModel.shared.storage.totalDiskStorageSize ?? 0) +
2022-12-11 22:34:39 +05:30
(VideosCacheModel.shared.storage.totalDiskStorageSize ?? 0) +
(PlaylistsCacheModel.shared.storage.totalDiskStorageSize ?? 0)
2022-12-10 07:31:59 +05:30
}
var totalSizeFormatted: String {
2022-12-11 22:34:39 +05:30
byteCountFormatter.string(fromByteCount: Int64(totalSize))
2022-12-10 07:31:59 +05:30
}
2022-12-11 22:34:39 +05:30
var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .medium
return formatter
}
var dateFormatterForTimeOnly: DateFormatter {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .medium
return formatter
2022-12-10 07:31:59 +05:30
}
2022-12-11 22:34:39 +05:30
var iso8601DateFormatter: ISO8601DateFormatter { .init() }
private var byteCountFormatter: ByteCountFormatter { .init() }
2022-11-10 22:41:28 +05:30
}