Skip to content

Commit b46caf8

Browse files
authored
invalidate cache during channel voting and centralize cache set to ensure cache is always populated when we have channels to use (#217)
1 parent 9da043b commit b46caf8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

llo/plugin_outcome.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,17 @@ func (p *Plugin) outcome(outctx ocr3types.OutcomeContext, query types.Query, aos
152152
}
153153
outcome.ChannelDefinitions[defWithID.ChannelID] = defWithID.ChannelDefinition
154154

155-
// Parse and cache opts to avoid repeated JSON parsing where opts are needed
156-
p.parseAndCacheChannelOpts(defWithID.ChannelID, defWithID.ChannelDefinition)
155+
// Invalidate cache if the channel is added or updated
156+
p.ChannelDefinitionOptsCache.Delete(defWithID.ChannelID)
157+
}
158+
159+
// at this point the outcome.ChannelDefinitions is fully populated both from carry forward of previousOutcome
160+
// and from the new channels added/updated via voting.
161+
// only once we've assembled the outcome.ChannelDefinitions we should cache the opts for all channels.
162+
for channelID, cd := range outcome.ChannelDefinitions {
163+
if _, cached := p.ChannelDefinitionOptsCache.Get(channelID); !cached {
164+
p.parseAndCacheChannelOpts(channelID, cd)
165+
}
157166
}
158167

159168
/////////////////////////////////

0 commit comments

Comments
 (0)