@@ -60,27 +60,32 @@ class DefaultCmabService {
6060 let userId = userContext. userId
6161
6262 if options. contains ( . ignoreCmabCache) {
63+ self . logger. i ( " Ignoring CMAB cache. " )
6364 fetchDecision ( ruleId: ruleId, userId: userId, attributes: filteredAttributes, completion: completion)
6465 return
6566 }
6667
6768 if options. contains ( . resetCmabCache) {
69+ self . logger. i ( " Resetting CMAB cache. " )
6870 cmabCache. reset ( )
6971 }
7072
7173 let cacheKey = getCacheKey ( userId: userId, ruleId: ruleId)
7274
7375 if options. contains ( . invalidateUserCmabCache) {
76+ self . logger. i ( " Invalidating user CMAB cache. " )
7477 self . cmabCache. remove ( key: cacheKey)
7578 }
7679
7780 let attributesHash = hashAttributes ( filteredAttributes)
7881
7982 if let cachedValue = cmabCache. lookup ( key: cacheKey) , cachedValue. attributesHash == attributesHash {
8083 let decision = CmabDecision ( variationId: cachedValue. variationId, cmabUUID: cachedValue. cmabUUID)
84+ self . logger. i ( " Returning cached CMAB decision. " )
8185 completion ( . success( decision) )
8286 return
8387 } else {
88+ self . logger. i ( " CMAB decision not found in cache. " )
8489 cmabCache. remove ( key: cacheKey)
8590 }
8691
@@ -91,6 +96,7 @@ class DefaultCmabService {
9196 variationId: decision. variationId,
9297 cmabUUID: decision. cmabUUID
9398 )
99+ self . logger. i ( " Featched CMAB decision and cached it. " )
94100 self . cmabCache. save ( key: cacheKey, value: cacheValue)
95101 }
96102 completion ( result)
@@ -105,9 +111,11 @@ class DefaultCmabService {
105111 cmabClient. fetchDecision ( ruleId: ruleId, userId: userId, attributes: attributes, cmabUUID: cmabUUID) { result in
106112 switch result {
107113 case . success( let variaitonId) :
114+ self . logger. i ( " Fetched CMAB decision: \( variaitonId) " )
108115 let decision = CmabDecision ( variationId: variaitonId, cmabUUID: cmabUUID)
109116 completion ( . success( decision) )
110117 case . failure( let error) :
118+ self . logger. e ( " Failed to fetch CMAB decision: \( error) " )
111119 completion ( . failure( error) )
112120 }
113121 }
0 commit comments