mirror of
https://github.com/hyperoslo/Cache.git
synced 2026-04-07 19:17:36 +00:00
29 lines
641 B
Swift
29 lines
641 B
Swift
import Foundation
|
|
|
|
/**
|
|
Helper class to hold cached instance and expiry date.
|
|
Used in memory storage to work with NSCache.
|
|
*/
|
|
final class Capsule: NSObject {
|
|
/// Object to be cached
|
|
let object: Any
|
|
/// Expiration date
|
|
let expiryDate: Date
|
|
/// Checks if cached object is expired according to expiration date
|
|
var isExpired: Bool {
|
|
return expiryDate.inThePast
|
|
}
|
|
|
|
// MARK: - Initialization
|
|
|
|
/**
|
|
Creates a new instance of Capsule.
|
|
- Parameter value: Object to be cached
|
|
- Parameter expiry: Expiration date
|
|
*/
|
|
init(value: Any, expiry: Expiry) {
|
|
self.object = value
|
|
self.expiryDate = expiry.date
|
|
}
|
|
}
|