Skip to content

Commit aed6c1f

Browse files
committed
Merge branch 'main' into feature/buffable-async-publishers
2 parents 2e76fd1 + 94eae2e commit aed6c1f

File tree

13 files changed

+193
-217
lines changed

13 files changed

+193
-217
lines changed

.github/workflows/pull_request_checks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
- name: 🗄️ Checkout Code
1515
uses: actions/checkout@v3
1616
- name: 🧰 Select Xcode Version
17-
run: sudo xcode-select -s "/Applications/Xcode_14.3.1.app/Contents/Developer"
17+
run: sudo xcode-select -s "/Applications/Xcode_15.0.app/Contents/Developer"
1818
- name: 🧪 Run tests
19-
run: xcodebuild test -scheme "swift-nibbles-Package" -testPlan "swift-nibbles-Package" -destination "OS=16.4,name=iPhone 14 Pro"
19+
run: xcodebuild test -scheme "swift-nibbles-Package" -testPlan "swift-nibbles-Package" -destination "OS=17.0,name=iPhone 15 Pro"
2020
- name: 📊 Upload Coverage
2121
uses: codecov/codecov-action@v3
2222
with:

.swiftpm/xcode/xcshareddata/xcschemes/Cache.xcscheme renamed to .swiftpm/xcode/xcshareddata/xcschemes/Stash.xcscheme

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "Cache"
18-
BuildableName = "Cache"
19-
BlueprintName = "Cache"
17+
BlueprintIdentifier = "Stash"
18+
BuildableName = "Stash"
19+
BlueprintName = "Stash"
2020
ReferencedContainer = "container:">
2121
</BuildableReference>
2222
</BuildActionEntry>
@@ -29,7 +29,7 @@
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<TestPlans>
3131
<TestPlanReference
32-
reference = "container:Tests/CacheTests/Cache.xctestplan"
32+
reference = "container:Tests/StashTests/Stash.xctestplan"
3333
default = "YES">
3434
</TestPlanReference>
3535
</TestPlans>
@@ -54,9 +54,9 @@
5454
<MacroExpansion>
5555
<BuildableReference
5656
BuildableIdentifier = "primary"
57-
BlueprintIdentifier = "Cache"
58-
BuildableName = "Cache"
59-
BlueprintName = "Cache"
57+
BlueprintIdentifier = "Stash"
58+
BuildableName = "Stash"
59+
BlueprintName = "Stash"
6060
ReferencedContainer = "container:">
6161
</BuildableReference>
6262
</MacroExpansion>

.swiftpm/xcode/xcshareddata/xcschemes/swift-nibbles-Package.xcscheme

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "Cache"
18-
BuildableName = "Cache"
19-
BlueprintName = "Cache"
17+
BlueprintIdentifier = "Stash"
18+
BuildableName = "Stash"
19+
BlueprintName = "Stash"
2020
ReferencedContainer = "container:">
2121
</BuildableReference>
2222
</BuildActionEntry>
@@ -70,9 +70,9 @@
7070
buildForAnalyzing = "YES">
7171
<BuildableReference
7272
BuildableIdentifier = "primary"
73-
BlueprintIdentifier = "CacheTests"
74-
BuildableName = "CacheTests"
75-
BlueprintName = "CacheTests"
73+
BlueprintIdentifier = "StashTests"
74+
BuildableName = "StashTests"
75+
BlueprintName = "StashTests"
7676
ReferencedContainer = "container:">
7777
</BuildableReference>
7878
</BuildActionEntry>
@@ -150,9 +150,9 @@
150150
skipped = "NO">
151151
<BuildableReference
152152
BuildableIdentifier = "primary"
153-
BlueprintIdentifier = "CacheTests"
154-
BuildableName = "CacheTests"
155-
BlueprintName = "CacheTests"
153+
BlueprintIdentifier = "StashTests"
154+
BuildableName = "StashTests"
155+
BlueprintName = "StashTests"
156156
ReferencedContainer = "container:">
157157
</BuildableReference>
158158
</TestableReference>
@@ -228,9 +228,9 @@
228228
<MacroExpansion>
229229
<BuildableReference
230230
BuildableIdentifier = "primary"
231-
BlueprintIdentifier = "Cache"
232-
BuildableName = "Cache"
233-
BlueprintName = "Cache"
231+
BlueprintIdentifier = "Stash"
232+
BuildableName = "Stash"
233+
BlueprintName = "Stash"
234234
ReferencedContainer = "container:">
235235
</BuildableReference>
236236
</MacroExpansion>

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ let package = Package(
1111
.watchOS(.v9),
1212
],
1313
products: [
14-
.library(name: "Cache", targets: ["Cache"]),
14+
.library(name: "Stash", targets: ["Stash"]),
1515
.library(name: "Extensions", targets: ["Extensions"]),
1616
.library(name: "Fuse", targets: ["Fuse"]),
1717
.library(name: "HTTPNetworking", targets: ["HTTPNetworking"]),
1818
.library(name: "Identified", targets: ["Identified"]),
1919
.plugin(name: "Create TCA Feature", targets: ["Create TCA Feature"])
2020
],
2121
targets: [
22-
.target(name: "Cache"),
23-
.testTarget(name: "CacheTests", dependencies: ["Cache"]),
22+
.target(name: "Stash"),
23+
.testTarget(name: "StashTests", dependencies: ["Stash"]),
2424

2525
.target(name: "Extensions"),
2626
.testTarget(name: "ExtensionsTests", dependencies: ["Extensions"]),

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ Nibbles are all broken down into their own targets, so you can choose which nibb
1919
```swift
2020
.product(name: "HTTPNetworking", package: "swift-nibbles")
2121
// or
22-
.product(name: "Cache", package: "swift-nibbles")
22+
.product(name: "Stash", package: "swift-nibbles")
2323
```
2424

2525
## Nibbles
2626

27-
### 🗄️ Cache
27+
### 🗄️ Stash
2828
A simple cache that can be used to store objects.
2929

30-
Use a cache to store objects of a given type in memory using an associated key.
31-
You can then fetch attempt to retrieve from the cache at a later time using the key.
30+
Use a `Stash` to store objects of a given type in memory using an associated key.
31+
You can then fetch attempt to retrieve from the `Stash` at a later time using the key.
3232

3333
### ⛓️ Extensions
3434
A collection of useful extensions that I freqeuntly implement across multiple projects.

Sources/Cache/Cache+Entry.swift renamed to Sources/Stash/Stash+Entry.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
import Foundation
2424

25-
extension Cache {
26-
/// A wrapper around the `Value` saved to the cache. This is what gets saved to the `NSCache`.
25+
extension Stash {
26+
/// A wrapper around the `Value` saved to the stash. This is what gets saved to the `NSCache`.
2727
final class Entry {
28-
/// The key that is used to lookup the value in the cache.
28+
/// The key that is used to lookup the value in the stash.
2929
let key: Key
30-
/// The value that is being cached.
30+
/// The value that is being stashdd.
3131
let value: Value
32-
/// The expiration date for the entry within the cache.
32+
/// The expiration date for the entry within the stash.
3333
let lifetime: Date
3434

3535
init(key: Key, value: Value, lifetime: Date) {
@@ -42,4 +42,4 @@ extension Cache {
4242

4343
// MARK: Entry + Codable
4444

45-
extension Cache.Entry: Codable where Key: Codable, Value: Codable {}
45+
extension Stash.Entry: Codable where Key: Codable, Value: Codable {}

Sources/Cache/Cache+KeyTracker.swift renamed to Sources/Stash/Stash+KeyTracker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import Foundation
2424

25-
extension Cache {
25+
extension Stash {
2626
/// Keeps track of the keys that are added and removed from an NSCache.
2727
final class KeyTracker: NSObject, NSCacheDelegate {
2828
var keys = Set<Key>()

Sources/Cache/Cache+WrappedKey.swift renamed to Sources/Stash/Stash+WrappedKey.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
import Foundation
2424

25-
extension Cache {
26-
/// A wrapper around the `Cache's` `Key` type that makes it compatible with `NSCache`
25+
extension Stash {
26+
/// A wrapper around the `Stash's` `Key` type that makes it compatible with `NSCache`
2727
class WrappedKey: NSObject {
2828

2929
// MARK: Properties

Sources/Cache/Cache.swift renamed to Sources/Stash/Stash.swift

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,46 @@
2222

2323
import Foundation
2424

25-
// MARK: - Cache
25+
// MARK: - Stash
2626

2727
/// A simple cache that can be used to store objects.
2828
///
29-
/// Use a cache to store objects of a given type in memory using an associated key.
30-
/// You can then fetch attempt to retrieve from the cache at a later time using the key.
29+
/// Use a ``Stash`` to store objects of a given type in memory using an associated key.
30+
/// You can then fetch attempt to retrieve from the ``Stash`` at a later time using the key.
3131
///
3232
/// ```swift
33-
/// // Create a cache of dogs.
34-
/// let cache = Cache<String, Dog>
33+
/// // Create a stash of dogs.
34+
/// let stash = Stash<String, Dog>
3535
///
36-
/// // Store a dog inside the cache.
36+
/// // Store a dog inside the stash.
3737
/// let fido = Dog(name: "Fido")
38-
/// cache.insert(fido, forKey: "1")
38+
/// stash.insert(fido, forKey: "1")
3939
///
40-
/// // Retrieve a dog from the cache.
41-
/// let cachedDog = cache.value(forKey: "1")
40+
/// // Retrieve a dog from the stash.
41+
/// let stashdDog = stash.value(forKey: "1")
4242
///
43-
/// // Remove a dog from the cache.
44-
/// cache.removeValue(forKey: "1")
43+
/// // Remove a dog from the stash.
44+
/// stash.removeValue(forKey: "1")
4545
///
46-
/// // Interact with the cache using subscripts.
47-
/// cache["2"] = Dog(name: "Spark")
48-
/// let otherCachedDog = cache["2"]
46+
/// // Interact with the stash using subscripts.
47+
/// stash["2"] = Dog(name: "Spark")
48+
/// let otherStasheedDog = stash["2"]
4949
/// ```
5050
///
51-
/// The cache implements a default limetime for which an item is considered valid. If you fetch an object
52-
/// from the cache and it has existed beyond the cache's specified lifetime, the cached object will be removed
51+
/// The stash implements a default limetime for which an item is considered valid. If you fetch an object
52+
/// from the stash and it has existed beyond the stash's specified lifetime, the stashd object will be removed
5353
/// and the retrievel will fail, returning a null value.
5454
///
5555
/// If both your key and the object you are storing are `Codable`, you can persist
56-
/// your cache to disk and load it at a later point in time.
57-
public final class Cache<Key: Hashable, Value> {
56+
/// your stash to disk and load it at a later point in time.
57+
public final class Stash<Key: Hashable, Value> {
5858

5959
// MARK: Properties
6060

61-
/// The provider used to create dates for cache entries.
61+
/// The provider used to create dates for stash entries.
6262
let dateProvider: () -> Date
6363

64-
/// The max lifetime that a value should exist in the cache.
64+
/// The max lifetime that a value should exist in the stash.
6565
let lifetime: TimeInterval
6666

6767
/// The actual cache store.
@@ -70,19 +70,19 @@ public final class Cache<Key: Hashable, Value> {
7070
/// An observer of the store.
7171
let keyTracker = KeyTracker()
7272

73-
/// The keys that currently exist within the cache.
73+
/// The keys that currently exist within the stash.
7474
public var keys: Set<Key> {
7575
return keyTracker.keys
7676
}
7777

7878
// MARK: Initializers
7979

80-
/// Creates a cache with the provided configuration.
80+
/// Creates a stash with the provided configuration.
8181
///
8282
/// - Parameters:
83-
/// - dateProvider: The provider used to create dates for cache entries.
84-
/// - lifetime: The max lifetime that a value should exist in the cache.
85-
/// - limit: The max number of items that should exist in the cache.
83+
/// - dateProvider: The provider used to create dates for stash entries.
84+
/// - lifetime: The max lifetime that a value should exist in the stash.
85+
/// - limit: The max number of items that should exist in the stash.
8686
public init(
8787
dateProvider: @escaping () -> Date = Date.init,
8888
lifetime: TimeInterval = 12 * 60 * 60,
@@ -96,7 +96,7 @@ public final class Cache<Key: Hashable, Value> {
9696

9797
// MARK: Actions
9898

99-
/// Inserts the provided value into the cache.
99+
/// Inserts the provided value into the stash.
100100
///
101101
/// - Parameters:
102102
/// - value: The value to be inserted.
@@ -107,17 +107,17 @@ public final class Cache<Key: Hashable, Value> {
107107
insert(entry)
108108
}
109109

110-
/// Retrieves the value for the provided key from the cache.
110+
/// Retrieves the value for the provided key from the stash.
111111
///
112-
/// - Parameter key: The key used to lookup the value in the cache.
112+
/// - Parameter key: The key used to lookup the value in the stash.
113113
/// - Returns: Returns the value if it exists, otherwise nil.
114114
public func value(forKey key: Key) -> Value? {
115115
entry(forKey: key)?.value
116116
}
117117

118-
/// Deletes the value in the cache for the provided key.
118+
/// Deletes the value in the stash for the provided key.
119119
///
120-
/// - Parameter key: The key used to lookup the value in the cache.
120+
/// - Parameter key: The key used to lookup the value in the stash.
121121
public func removeValue(forKey key: Key) {
122122
store.removeObject(forKey: WrappedKey(key))
123123
}
@@ -137,7 +137,7 @@ public final class Cache<Key: Hashable, Value> {
137137

138138
// MARK: Private Actions
139139

140-
/// Inserts the provided entry into the cache.
140+
/// Inserts the provided entry into the stash.
141141
///
142142
/// - Parameters:
143143
/// - entry: The entry to be inserted.
@@ -146,7 +146,7 @@ public final class Cache<Key: Hashable, Value> {
146146
keyTracker.keys.insert(entry.key)
147147
}
148148

149-
/// Gets the cache entry for the provided key.
149+
/// Gets the stash entry for the provided key.
150150
///
151151
/// - Parameter key: The key used to lookup the entry.
152152
/// - Returns: The entry, if it exists, otherwise nil.
@@ -164,9 +164,9 @@ public final class Cache<Key: Hashable, Value> {
164164
}
165165
}
166166

167-
// MARK: - Cache + Codable
167+
// MARK: - Stash + Codable
168168

169-
extension Cache: Codable where Key: Codable, Value: Codable {
169+
extension Stash: Codable where Key: Codable, Value: Codable {
170170
public convenience init(from decoder: Decoder) throws {
171171
self.init()
172172

@@ -180,35 +180,35 @@ extension Cache: Codable where Key: Codable, Value: Codable {
180180
try container.encode(keyTracker.keys.compactMap(entry))
181181
}
182182

183-
/// Saves the cache to disk for long-term storage.
183+
/// Saves the stash to disk for long-term storage.
184184
///
185185
/// - Parameters:
186-
/// - name: The name of the cache file.
187-
/// - fileManager: The file manager that should store the cache.
186+
/// - name: The name of the stash file.
187+
/// - fileManager: The file manager that should store the stash.
188188
public func saveToDisk(withName name: String, using fileManager: FileManager = .default) throws {
189189
let folderURLs = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)
190-
let fileURL = folderURLs[0].appendingPathComponent(name + ".cache")
190+
let fileURL = folderURLs[0].appendingPathComponent(name + ".stash")
191191
let data = try JSONEncoder().encode(self)
192192
try data.write(to: fileURL)
193193
}
194194

195-
/// Loads a cache from disk, initializing it for usage.
195+
/// Loads a stash from disk, initializing it for usage.
196196
///
197197
/// - Parameters:
198-
/// - name: The name of the cache file.
198+
/// - name: The name of the stash file.
199199
/// - keyType: The type
200-
/// - valueType: The type of item being stored in the cache.
201-
/// - fileManager: The file manager that should load the cache from disk.
202-
/// - Returns: A cache initialized with the stored data.
200+
/// - valueType: The type of item being stored in the stash.
201+
/// - fileManager: The file manager that should load the stash from disk.
202+
/// - Returns: A stash initialized with the stored data.
203203
public static func loadFromDisk(
204204
withName name: String,
205205
keyType: Key.Type,
206206
valueType: Value.Type,
207207
using fileManager: FileManager = .default
208-
) throws -> Cache<Key, Value> {
208+
) throws -> Stash<Key, Value> {
209209
let folderURLs = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)
210-
let fileURL = folderURLs[0].appendingPathComponent(name + ".cache")
210+
let fileURL = folderURLs[0].appendingPathComponent(name + ".stash")
211211
let data = try Data(contentsOf: fileURL)
212-
return try JSONDecoder().decode(Cache<Key, Value>.self, from: data)
212+
return try JSONDecoder().decode(Stash<Key, Value>.self, from: data)
213213
}
214214
}

0 commit comments

Comments
 (0)