yattee/Model/VideoCacheModel.swift
2022-12-04 13:32:22 +01:00

24 lines
687 B
Swift

import Foundation
import Logging
import SwiftyJSON
struct VideoCacheModel {
static let shared = VideoCacheModel()
var logger = Logger(label: "stream.yattee.video-cache")
func saveVideo(id: Video.ID, app: VideosApp, json: JSON) {
guard !json.isEmpty else { return }
var jsonWithApp = json
jsonWithApp["app"].string = app.rawValue
try! CacheModel.shared.videoStorage!.setObject(jsonWithApp, forKey: id)
logger.info("saving video \(id)")
}
func loadVideo(id: Video.ID) -> JSON? {
logger.info("loading video \(id)")
let json = try? CacheModel.shared.videoStorage?.object(forKey: id)
return json
}
}