@@ -60,27 +60,32 @@ class DefaultCmabService {
60
60
let userId = userContext. userId
61
61
62
62
if options. contains ( . ignoreCmabCache) {
63
+ self . logger. i ( " Ignoring CMAB cache. " )
63
64
fetchDecision ( ruleId: ruleId, userId: userId, attributes: filteredAttributes, completion: completion)
64
65
return
65
66
}
66
67
67
68
if options. contains ( . resetCmabCache) {
69
+ self . logger. i ( " Resetting CMAB cache. " )
68
70
cmabCache. reset ( )
69
71
}
70
72
71
73
let cacheKey = getCacheKey ( userId: userId, ruleId: ruleId)
72
74
73
75
if options. contains ( . invalidateUserCmabCache) {
76
+ self . logger. i ( " Invalidating user CMAB cache. " )
74
77
self . cmabCache. remove ( key: cacheKey)
75
78
}
76
79
77
80
let attributesHash = hashAttributes ( filteredAttributes)
78
81
79
82
if let cachedValue = cmabCache. lookup ( key: cacheKey) , cachedValue. attributesHash == attributesHash {
80
83
let decision = CmabDecision ( variationId: cachedValue. variationId, cmabUUID: cachedValue. cmabUUID)
84
+ self . logger. i ( " Returning cached CMAB decision. " )
81
85
completion ( . success( decision) )
82
86
return
83
87
} else {
88
+ self . logger. i ( " CMAB decision not found in cache. " )
84
89
cmabCache. remove ( key: cacheKey)
85
90
}
86
91
@@ -91,6 +96,7 @@ class DefaultCmabService {
91
96
variationId: decision. variationId,
92
97
cmabUUID: decision. cmabUUID
93
98
)
99
+ self . logger. i ( " Featched CMAB decision and cached it. " )
94
100
self . cmabCache. save ( key: cacheKey, value: cacheValue)
95
101
}
96
102
completion ( result)
@@ -105,9 +111,11 @@ class DefaultCmabService {
105
111
cmabClient. fetchDecision ( ruleId: ruleId, userId: userId, attributes: attributes, cmabUUID: cmabUUID) { result in
106
112
switch result {
107
113
case . success( let variaitonId) :
114
+ self . logger. i ( " Fetched CMAB decision: \( variaitonId) " )
108
115
let decision = CmabDecision ( variationId: variaitonId, cmabUUID: cmabUUID)
109
116
completion ( . success( decision) )
110
117
case . failure( let error) :
118
+ self . logger. e ( " Failed to fetch CMAB decision: \( error) " )
111
119
completion ( . failure( error) )
112
120
}
113
121
}
0 commit comments