Skip to content

Commit 0073f13

Browse files
committed
Don't update expires in MemoryPersistDriver.set if it is nil
1 parent 3214185 commit 0073f13

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Sources/Hummingbird/Storage/MemoryPersistDriver.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public actor MemoryPersistDriver<C: Clock>: PersistDriver where C.Duration == Du
2929
}
3030

3131
public func set(key: String, value: some Codable & Sendable, expires: Duration?) async throws {
32-
self.values[key] = .init(value: value, expires: expires.map { self.clock.now.advanced(by: $0) })
32+
let expiresAt = expires.map { self.clock.now.advanced(by: $0) } ?? self.values[key]?.expires
33+
self.values[key] = .init(value: value, expires: expiresAt)
3334
}
3435

3536
public func get<Object: Codable & Sendable>(key: String, as: Object.Type) async throws -> Object? {

Sources/Hummingbird/Storage/PersistDriver.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public protocol PersistDriver: Service {
3131
/// - Parameters:
3232
/// - key: Key to store value against
3333
/// - value: Codable value to store
34-
/// - expires: If non-nil defines time that value will expire
34+
/// - expires: If non-nil defines time that value will expire in. If nil and value already exists
35+
/// and it already has an expiration time then original expiration time should be conserved.
3536
func set<Object: Codable & Sendable>(key: String, value: Object, expires: Duration?) async throws
3637

3738
/// get value for key

0 commit comments

Comments
 (0)