alibaba/nacos · error · IllegalArgumentException

min default cache time is too small(<1000)

Error message

min default cache time  is too small(<1000)

What it means

Thrown when entry is 'defaultCacheMillis' and the parsed long is below MIN_CACHE_TIME_MIILIS (1000 ms). This is the default client cache interval for clients without push enabled. The source comment warns: 'extremely careful while modifying this, cause it will affect all clients without pushing enabled.'

Source

Thrown at naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java:176

            }
            
            if (entry.equals(SwitchEntry.PUSH_CACHE_MILLIS)) {
                long cacheMillis = Long.parseLong(value);
                
                if (cacheMillis < SwitchEntry.MIN_PUSH_CACHE_TIME_MIILIS) {
                    throw new IllegalArgumentException(
                        "min cache time for http or tcp is too small(<10000)");
                }
                
                tempSwitchDomain.setDefaultPushCacheMillis(cacheMillis);
            }
            
            // extremely careful while modifying this, cause it will affect all clients without pushing enabled
            if (entry.equals(SwitchEntry.DEFAULT_CACHE_MILLIS)) {
                long cacheMillis = Long.parseLong(value);
                
                if (cacheMillis < SwitchEntry.MIN_CACHE_TIME_MIILIS) {
                    throw new IllegalArgumentException(
                        "min default cache time  is too small(<1000)");
                }
                
                tempSwitchDomain.setDefaultCacheMillis(cacheMillis);
            }
            
            if (entry.equals(SwitchEntry.MASTERS)) {
                List<String> masters = Arrays.asList(value.split(","));
                tempSwitchDomain.setMasters(masters);
            }
            
            if (entry.equals(SwitchEntry.DISTRO)) {
                boolean enabled = Boolean.parseBoolean(value);
                tempSwitchDomain.setDistroEnabled(enabled);
            }
            
            if (entry.equals(SwitchEntry.CHECK) || entry.equals(SwitchEntry.HEALTH_CHECK_ENABLED)) {
                boolean enabled = Boolean.parseBoolean(value);

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Set defaultCacheMillis to >= 1000 (1 second).
  2. Verify the value is in milliseconds.
  3. Understand that lowering this affects ALL non-push clients globally.

Example fix

// before
PUT /v3/admin/ns/operator/switches?entry=defaultCacheMillis&value=500
// after
PUT /v3/admin/ns/operator/switches?entry=defaultCacheMillis&value=1000
Defensive patterns

Strategy: validation

Validate before calling

long cacheMillis = Long.parseLong(value);
if (cacheMillis < 1000) {
    throw new IllegalArgumentException("defaultCacheMillis must be >= 1000");
}

Type guard

function isValidDefaultCacheMillis(v: number): boolean {
  return v >= 1000;
}

Try / catch

try {
  operatorV2Impl.updateSwitch("defaultCacheMillis", String.valueOf(cacheMillis), debug);
} catch (NacosApiException e) {
  if (e.getMessage().contains("too small")) {
    cacheMillis = 1000;
  }
}

Prevention

When it happens

Trigger: PUT /v3/admin/ns/operator/switches with entry=defaultCacheMillis and value < 1000, e.g. value=500, value=100, value=0.

Common situations: Passing seconds instead of milliseconds, or trying to reduce polling interval below the safety floor of 1 second.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/c0ea07386239ba9b. Report an issue: GitHub.