1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Model/Cache/BaseCacheModel.swift

38 lines
1.0 KiB
Swift
Raw Normal View History

2022-12-12 14:51:46 +05:30
import Cache
import Foundation
import Logging
import SwiftyJSON
struct BaseCacheModel {
static var shared = BaseCacheModel()
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)
var models: [CacheModel] {
[
FeedCacheModel.shared,
VideosCacheModel.shared,
2022-12-14 04:37:32 +05:30
ChannelsCacheModel.shared,
2022-12-12 14:51:46 +05:30
PlaylistsCacheModel.shared,
ChannelPlaylistsCacheModel.shared,
SubscribedChannelsModel.shared
]
}
func clear() {
models.forEach { $0.clear() }
}
var totalSize: Int {
models.compactMap { $0.storage?.totalDiskStorageSize }.reduce(0, +)
}
var totalSizeFormatted: String {
byteCountFormatter.string(fromByteCount: Int64(totalSize))
}
private var byteCountFormatter: ByteCountFormatter { .init() }
}