31 lines
589 B
Swift
31 lines
589 B
Swift
//
|
|
// CacheExpiry.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 1/18/21.
|
|
// Copyright © 2021 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum CacheExpiry {
|
|
case never
|
|
case seconds(TimeInterval)
|
|
case date(Date)
|
|
|
|
var date: Date {
|
|
switch self {
|
|
case .never:
|
|
return .distantFuture
|
|
case let .seconds(seconds):
|
|
return Date().addingTimeInterval(seconds)
|
|
case let .date(date):
|
|
return date
|
|
}
|
|
}
|
|
|
|
var isExpired: Bool {
|
|
return date.timeIntervalSinceNow < 0
|
|
}
|
|
}
|