Skip to content

Commit 4dc2f8e

Browse files
committed
Update PR from comments on PR
1 parent ac60ea0 commit 4dc2f8e

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

Sources/Cache/Cache/AnyCacheable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class AnyCacheable: Cacheable, @unchecked Sendable {
115115
guard let output = resolvedValue as? Output else {
116116
throw InvalidTypeError(
117117
expectedType: Output.self,
118-
actualType: type(of: cacheGet(key))
118+
actualType: Value.self
119119
)
120120
}
121121
return output

Sources/Cache/Cache/PersistableCache.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import Foundation
4343
public class PersistableCache<
4444
Key: RawRepresentable & Hashable, Value, PersistedValue
4545
>: Cache<Key, Value>, @unchecked Sendable where Key.RawValue == String {
46-
private let persistLock = CacheLock()
4746

4847
/// The name of the cache. This will be used as the filename when saving to disk.
4948
public let name: String
@@ -150,8 +149,8 @@ public class PersistableCache<
150149
- An error if the `data.write(to:)` call fails to write the JSON data to disk.
151150
*/
152151
public func save() throws {
153-
try persistLock.withLock {
154-
let persistedValues = allValues.compactMapValues(persistedValueMap)
152+
try lock.withLock {
153+
let persistedValues = unsafeValues(ofType: Value.self).compactMapValues(persistedValueMap)
155154
let json = JSON<Key>(initialValues: persistedValues)
156155
let data = try json.data()
157156
try data.write(to: url.fileURL(withName: name))
@@ -164,7 +163,7 @@ public class PersistableCache<
164163
- Throws: An error if the file manager fails to remove the cache file.
165164
*/
166165
public func delete() throws {
167-
try persistLock.withLock {
166+
try lock.withLock {
168167
try FileManager.default.removeItem(at: url.fileURL(withName: name))
169168
}
170169
}

0 commit comments

Comments
 (0)