Skip to content

Commit d427da3

Browse files
committed
feat: 编译xcframework
1 parent 942e43e commit d427da3

File tree

4 files changed

+357
-7
lines changed

4 files changed

+357
-7
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import PackageDescription
66
let package = Package(
77
name: "CacheKit",
88
platforms: [
9-
.macOS(.v11), .iOS(.v13), .tvOS(.v13)
9+
.macOS(.v11), .iOS(.v13), .tvOS(.v13), .visionOS(.v1)
1010
],
1111
products: [
1212
// Products define the executables and libraries a package produces, making them visible to other packages.
1313
.library(
1414
name: "CacheKit",
15+
type: .dynamic,
1516
targets: ["CacheKit"]),
1617
],
1718
dependencies: [

Sources/CacheKit/CacheEntry.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public final class CacheEntry<V> {
1616
/// - key: The unique identifier for the cached value
1717
/// - value: The value to be cached
1818
/// - expiredTimestamp: The date when the cache entry expires
19-
init(key: String, value: V, expiredTimestamp: Date) {
19+
public init(key: String, value: V, expiredTimestamp: Date) {
2020
self.key = key
2121
self.value = value
2222
self.expiredTimestamp = expiredTimestamp
@@ -41,4 +41,23 @@ public final class CacheEntry<V> {
4141
}
4242
}
4343

44-
extension CacheEntry: Codable where V: Codable {}
44+
extension CacheEntry: Codable where V: Codable {
45+
private enum CodingKeys: String, CodingKey {
46+
case key, value, expiredTimestamp
47+
}
48+
49+
public func encode(to encoder: Encoder) throws {
50+
var container = encoder.container(keyedBy: CodingKeys.self)
51+
try container.encode(key, forKey: .key)
52+
try container.encode(value, forKey: .value)
53+
try container.encode(expiredTimestamp, forKey: .expiredTimestamp)
54+
}
55+
56+
public convenience init(from decoder: Decoder) throws {
57+
let container = try decoder.container(keyedBy: CodingKeys.self)
58+
let key = try container.decode(String.self, forKey: .key)
59+
let value = try container.decode(V.self, forKey: .value)
60+
let expiredTimestamp = try container.decode(Date.self, forKey: .expiredTimestamp)
61+
self.init(key: key, value: value, expiredTimestamp: expiredTimestamp)
62+
}
63+
}

Sources/CacheKit/CacheImplementation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public actor DiskCache<V: Codable>: NSCacheType {
8989
public extension NSCacheType {
9090
/// Removes a value from the cache.
9191
/// - Parameter key: The key to remove.
92-
public func removeValue(forKey key: String) {
92+
func removeValue(forKey key: String) {
9393
keysTracker.keys.remove(key)
9494
cache.removeObject(forKey: key as NSString)
9595
}
9696

9797
/// Removes all values from the cache.
98-
public func removeAllValues() {
98+
func removeAllValues() {
9999
keysTracker.keys.removeAll()
100100
cache.removeAllObjects()
101101
}
@@ -104,7 +104,7 @@ public extension NSCacheType {
104104
/// - Parameters:
105105
/// - value: The value to store. If nil, the key will be removed.
106106
/// - key: The key to associate with the value.
107-
public func setValue(_ value: V?, forKey key: String) {
107+
func setValue(_ value: V?, forKey key: String) {
108108
if let value {
109109
let expiredTimestamp = Date().addingTimeInterval(expirationInterval)
110110
let cacheEntry = CacheEntry(key: key, value: value, expiredTimestamp: expiredTimestamp)
@@ -117,7 +117,7 @@ public extension NSCacheType {
117117
/// Retrieves a value from the cache.
118118
/// - Parameter key: The key to look up.
119119
/// - Returns: The value associated with the key, or nil if no value exists or has expired.
120-
public func value(forKey key: String) -> V? {
120+
func value(forKey key: String) -> V? {
121121
entry(forKey: key)?.value
122122
}
123123

0 commit comments

Comments
 (0)