Skip to content

Commit bfe5e90

Browse files
committed
populate gethomeaz cache if it is not populated when DNC calls CNS to get home az
1 parent f2d2be5 commit bfe5e90

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

cns/restserver/homeazmonitor.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/Azure/azure-container-networking/cns/logger"
1111
"github.com/Azure/azure-container-networking/cns/types"
1212
"github.com/Azure/azure-container-networking/nmagent"
13-
"github.com/patrickmn/go-cache"
1413
"github.com/pkg/errors"
1514
)
1615

@@ -50,14 +49,25 @@ func (h *HomeAzMonitor) updateCacheValue(resp cns.GetHomeAzResponse) {
5049

5150
// readCacheValue reads home az cache value
5251
func (h *HomeAzMonitor) readCacheValue() cns.GetHomeAzResponse {
53-
cachedResp, found := h.values.Get(homeAzCacheKey)
54-
if !found {
55-
return cns.GetHomeAzResponse{Response: cns.Response{
52+
if cachedResp, found := h.values.Get(homeAzCacheKey); found {
53+
return cachedResp.(cns.GetHomeAzResponse)
54+
}
55+
56+
ctx, cancel := context.WithTimeout(context.Background(), ContextTimeOut)
57+
defer cancel()
58+
h.Populate(ctx)
59+
60+
if cachedResp, found := h.values.Get(homeAzCacheKey); found {
61+
return cachedResp.(cns.GetHomeAzResponse)
62+
}
63+
64+
return cns.GetHomeAzResponse{
65+
Response: cns.Response{
5666
ReturnCode: types.NotFound,
5767
Message: "HomeAz Cache is unavailable",
58-
}, HomeAzResponse: cns.HomeAzResponse{IsSupported: false}}
68+
},
69+
HomeAzResponse: cns.HomeAzResponse{IsSupported: false},
5970
}
60-
return cachedResp.(cns.GetHomeAzResponse)
6171
}
6272

6373
// Start starts a new thread to refresh home az cache

0 commit comments

Comments
 (0)