Skip to content

Commit

Permalink
Fixing a cache read issue (#42)
Browse files Browse the repository at this point in the history
* Fixing a cache read issue

* Update CacheTest.swift
  • Loading branch information
z4kn4fein authored Mar 27, 2024
1 parent b2330ff commit da6beca
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ConfigCat.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "ConfigCat"
spec.version = "11.0.0"
spec.version = "11.0.1"
spec.summary = "ConfigCat Swift SDK"
spec.swift_version = "5.0"

Expand Down
2 changes: 1 addition & 1 deletion ConfigCat.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator watchos watchsimulator app
SWIFT_VERSION = 5.0

// ConfigCat SDK version
MARKETING_VERSION = 11.0.0
MARKETING_VERSION = 11.0.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The following device platform versions are supported:
``` swift
dependencies: [
.package(url: "https://github.com/configcat/swift-sdk", from: "11.0.0")
.package(url: "https://github.com/configcat/swift-sdk", from: "11.0.1")
]
```
Expand Down
2 changes: 1 addition & 1 deletion Sources/ConfigCat/ConfigService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class ConfigService {
defer { mutex.unlock() }
// Sync up with the cache and use it when it's not expired.
let entry = readCache()
if cachedEntry.isEmpty && entry != cachedEntry {
if !entry.isEmpty && entry != cachedEntry {
cachedEntry = entry
hooks.invokeOnConfigChanged(config: entry.config)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ConfigCat/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Equatable {
}

class Constants {
static let version: String = "11.0.0"
static let version: String = "11.0.1"
static let configJsonName: String = "config_v6.json"
static let configJsonCacheVersion: String = "v2"
static let globalBaseUrl: String = "https://cdn-global.configcat.com"
Expand Down
25 changes: 25 additions & 0 deletions Tests/ConfigCatTests/CacheTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,29 @@ class CacheTests: XCTestCase {
XCTAssertEqual(testJson, fromCache.configJson)
XCTAssertEqual("test-etag", fromCache.eTag)
}

#if compiler(>=5.5) && canImport(_Concurrency)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func testCacheTTLRespectsExternalCache() async {
let testJson = "{\"f\":{\"testKey\":{\"t\":1,\"v\":{\"s\":\"%@\"}}}}"
let engine = MockEngine()
engine.enqueueResponse(response: Response(body: String(format: testJson, "remote"), statusCode: 200))

let entry = try! ConfigEntry.fromConfigJson(json: String(format: testJson, "local"), eTag: "test-etag", fetchTime: Date()).get()
let cache = SingleValueCache(initValue: entry.serialize())
let client = ConfigCatClient(sdkKey: randomSdkKey(), pollingMode: PollingModes.lazyLoad(cacheRefreshIntervalInSeconds: 1), logger: NoLogger(), httpEngine: engine, configCache: cache)
var val = await client.getValue(for: "testKey", defaultValue: "")

XCTAssertEqual("local", val)
XCTAssertEqual(0, engine.requests.count)

let entry2 = try! ConfigEntry.fromConfigJson(json: String(format: testJson, "local2"), eTag: "test-etag2", fetchTime: Date()).get()
try! cache.write(for: "", value: entry2.serialize())

val = await client.getValue(for: "testKey", defaultValue: "")

XCTAssertEqual("local2", val)
XCTAssertEqual(0, engine.requests.count)
}
#endif
}

0 comments on commit da6beca

Please sign in to comment.