         do {
             let data = try JSONEncoder().encode(channelsToSave)
             try data.write(to: url, options: [])
-            UserDefaults.standard.set(1, forKey: "key")
+            UserDefaults.standard.set(Date(), forKey: "SomaAPI.Cache.Timestamp")
         } catch {
             print("SomaAPI: Error saving channels to disk")
         }

public struct SomaAPI {
    static var channels: [Channel]? {
        didSet {
            NotificationCenter.default.post(name: .somaApiChannelsUpdated, object: nil)
        }
    }

    static let channelsURL = URL(string: "https://api.somafm.com/channels.json")!

    static func loadChannelsFromAPI() {
        if channels != nil,
            let cacheTimestamp = UserDefaults.standard.object(forKey: "SomaAPI.Cache.Timestamp") as? Date,
            Date().timeIntervalSince(cacheTimestamp) < 3*60 {
            // channels are still fresh, do not update
            return
        }

        let session = URLSession(configuration: URLSessionConfiguration.default)
        let request = URLRequest(url: channelsURL)

