Skip to content

Commit 2e0cb3d

Browse files
authored
fix: fixes disable cache flow (#369)
Signed-off-by: Nilekh Chaudhari <[email protected]>
1 parent 3eb381c commit 2e0cb3d

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

constraint/pkg/client/drivers/rego/builtin.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *
3838

3939
prepareResponse.Idempotent = true
4040
for _, k := range regoReq.Keys {
41+
if d.providerResponseCache == nil {
42+
// external data response cache is not enabled, add key to call provider
43+
providerRequestKeys = append(providerRequestKeys, k)
44+
continue
45+
}
46+
4147
cachedResponse, err := d.providerResponseCache.Get(
4248
externaldata.CacheKey{
4349
ProviderName: regoReq.ProviderName,
@@ -70,19 +76,22 @@ func externalDataBuiltin(d *Driver) func(bctx rego.BuiltinContext, regorequest *
7076
return externaldata.HandleError(statusCode, err)
7177
}
7278

73-
for _, item := range externaldataResponse.Response.Items {
74-
d.providerResponseCache.Upsert(
75-
externaldata.CacheKey{
76-
ProviderName: regoReq.ProviderName,
77-
Key: item.Key,
78-
},
79-
externaldata.CacheValue{
80-
Received: time.Now().Unix(),
81-
Value: item.Value,
82-
Error: item.Error,
83-
Idempotent: externaldataResponse.Response.Idempotent,
84-
},
85-
)
79+
// update provider response cache if it is enabled
80+
if d.providerResponseCache != nil {
81+
for _, item := range externaldataResponse.Response.Items {
82+
d.providerResponseCache.Upsert(
83+
externaldata.CacheKey{
84+
ProviderName: regoReq.ProviderName,
85+
Key: item.Key,
86+
},
87+
externaldata.CacheValue{
88+
Received: time.Now().Unix(),
89+
Value: item.Value,
90+
Error: item.Error,
91+
Idempotent: externaldataResponse.Response.Idempotent,
92+
},
93+
)
94+
}
8695
}
8796

8897
// we are taking conservative approach here, if any of the response is not idempotent

0 commit comments

Comments
 (0)