Skip to content

Commit

Permalink
Convert AtlasCache Logger to an instance property (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsinga committed Mar 6, 2024
1 parent 160d1d3 commit d053bf6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Sources/Site/Music/AtlasCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import CoreLocation
import Foundation
import os

extension Logger {
static let atlasCache = Logger(category: "atlasCache")
}

private let expirationOffset = 60.0 * 60.0 * 24.0 * 30.0 * 6.0 // Six months
private let ExpirationStaggerDuration = 60.0 * 60.0 * 6.0 // Quarter day

Expand All @@ -27,6 +23,8 @@ actor AtlasCache<T: AtlasGeocodable> {

private var staggerOffset = 0.0
private var cache: [T: Value] = [:]

private let atlasCache = Logger(category: "atlasCache")

internal init(fileName: String = "atlas.json") {
self.fileName = fileName
Expand All @@ -37,11 +35,11 @@ actor AtlasCache<T: AtlasGeocodable> {
self.cache = diskCache.filter { $0.value.expirationDate >= now } // Include those whose expiration date has not passed .now

if self.cache.count != diskCache.count {
Logger.atlasCache.log("removing expired items")
atlasCache.log("removing expired items")
try self.cache.save(fileName: fileName) // Some expired, so re-write the file.
}
} catch {
Logger.atlasCache.error("Cache Read Error: \(error, privacy: .public)")
atlasCache.error("Cache Read Error: \(error, privacy: .public)")
self.cache = [:]
}
}
Expand All @@ -68,7 +66,7 @@ actor AtlasCache<T: AtlasGeocodable> {
do {
try cache.save(fileName: fileName)
} catch {
Logger.atlasCache.error("Cache Save Error: \(error, privacy: .public)")
atlasCache.error("Cache Save Error: \(error, privacy: .public)")
}
}
}
Expand Down

0 comments on commit d053bf6

Please sign in to comment.