Skip to content

Commit

Permalink
fix: Use stable encoding format to increase cache hits (#267)
Browse files Browse the repository at this point in the history
There are several bits of information that can contribute to upstream
service cache hits. One of these is the shape of the context payload. By
maintaining a stable encoding format, we can increase the likelihood of
a cache hit.
  • Loading branch information
keelerm84 committed Dec 29, 2023
1 parent a74101d commit a134b84
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LaunchDarkly/LaunchDarkly/Networking/DarklyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ final class DarklyService: DarklyServiceProvider {
guard hasMobileKey(#function) else { return }
let encoder = JSONEncoder()
encoder.userInfo[LDContext.UserInfoKeys.includePrivateAttributes] = true
encoder.outputFormatting = [.sortedKeys]

guard let contextJsonData = try? encoder.encode(context)
else {
Log.debug(typeName(and: #function, appending: ": ") + "Aborting. Unable to create flagRequest.")
Expand Down Expand Up @@ -156,6 +158,7 @@ final class DarklyService: DarklyServiceProvider {
errorHandler: ConnectionErrorHandler?) -> DarklyStreamingProvider {
let encoder = JSONEncoder()
encoder.userInfo[LDContext.UserInfoKeys.includePrivateAttributes] = true
encoder.outputFormatting = [.sortedKeys]
let contextJsonData = try? encoder.encode(context)

var streamRequestUrl = config.streamUrl.appendingPathComponent(StreamRequestPath.meval)
Expand Down

0 comments on commit a134b84

Please sign in to comment.