@@ -154,6 +154,11 @@ func (ss *scaleSet) gcVMSSVMCache() error {
154
154
155
155
// newVMSSVirtualMachinesCache instanciates a new VMs cache for VMs belonging to the provided VMSS.
156
156
func (ss * scaleSet ) newVMSSVirtualMachinesCache (resourceGroupName , vmssName , cacheKey string ) (* azcache.TimedCache , error ) {
157
+ if ss .Config .VmssVirtualMachinesCacheTTLInSeconds == 0 {
158
+ ss .Config .VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
159
+ }
160
+ vmssVirtualMachinesCacheTTL := time .Duration (ss .Config .VmssVirtualMachinesCacheTTLInSeconds ) * time .Second
161
+
157
162
getter := func (key string ) (interface {}, error ) {
158
163
localCache := & sync.Map {} // [nodeName]*vmssVirtualMachinesEntry
159
164
@@ -212,9 +217,9 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cac
212
217
// add old missing cache data with nil entries to prevent aggressive
213
218
// ARM calls during cache invalidation
214
219
for name , vmEntry := range oldCache {
215
- // if the nil cache entry has existed for 15 minutes in the cache
220
+ // if the nil cache entry has existed for vmssVirtualMachinesCacheTTL in the cache
216
221
// then it should not be added back to the cache
217
- if vmEntry .virtualMachine == nil && time .Since (vmEntry .lastUpdate ) > 15 * time . Minute {
222
+ if vmEntry .virtualMachine == nil && time .Since (vmEntry .lastUpdate ) > vmssVirtualMachinesCacheTTL {
218
223
klog .V (5 ).Infof ("ignoring expired entries from old cache for %s" , name )
219
224
continue
220
225
}
@@ -238,10 +243,7 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cac
238
243
return localCache , nil
239
244
}
240
245
241
- if ss .Config .VmssVirtualMachinesCacheTTLInSeconds == 0 {
242
- ss .Config .VmssVirtualMachinesCacheTTLInSeconds = vmssVirtualMachinesCacheTTLDefaultInSeconds
243
- }
244
- return azcache .NewTimedcache (time .Duration (ss .Config .VmssVirtualMachinesCacheTTLInSeconds )* time .Second , getter )
246
+ return azcache .NewTimedcache (vmssVirtualMachinesCacheTTL , getter )
245
247
}
246
248
247
249
func (ss * scaleSet ) deleteCacheForNode (nodeName string ) error {
0 commit comments