Skip to content

Commit 5421f61

Browse files
committed
populate home az cache if it's not filled
1 parent bcd6fb7 commit 5421f61

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cns/restserver/homeazmonitor.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,25 @@ func (h *HomeAzMonitor) updateCacheValue(resp cns.GetHomeAzResponse) {
5050

5151
// readCacheValue reads home az cache value
5252
func (h *HomeAzMonitor) readCacheValue() cns.GetHomeAzResponse {
53-
cachedResp, found := h.values.Get(homeAzCacheKey)
54-
if !found {
55-
return cns.GetHomeAzResponse{Response: cns.Response{
53+
if cachedResp, found := h.values.Get(homeAzCacheKey); found {
54+
return cachedResp.(cns.GetHomeAzResponse)
55+
}
56+
57+
ctx, cancel := context.WithTimeout(context.Background(), ContextTimeOut)
58+
defer cancel()
59+
h.Populate(ctx)
60+
61+
if cachedResp, found := h.values.Get(homeAzCacheKey); found {
62+
return cachedResp.(cns.GetHomeAzResponse)
63+
}
64+
65+
return cns.GetHomeAzResponse{
66+
Response: cns.Response{
5667
ReturnCode: types.NotFound,
5768
Message: "HomeAz Cache is unavailable",
58-
}, HomeAzResponse: cns.HomeAzResponse{IsSupported: false}}
69+
},
70+
HomeAzResponse: cns.HomeAzResponse{IsSupported: false},
5971
}
60-
return cachedResp.(cns.GetHomeAzResponse)
6172
}
6273

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

0 commit comments

Comments
 (0)