MyCATApache/Mycat-Server · error · java.lang.RuntimeException

CachePoolFactory not defined for type

Error message

CachePoolFactory not defined for type:{type}

What it means

CacheService looks up a CachePoolFactory by cache type string (e.g. 'ehcache', 'leveldb', 'map') in the poolFactorys map populated from cache config. If the configured cache type has no registered factory, it throws this RuntimeException instead of returning a factory. It is a startup/config-level contract error: Mycat only supports the cache types it has factory implementations for.

Solutions

  1. Open your cache configuration and correct the cache type string to one Mycat supports (e.g. 'ehcache', 'map', 'leveldb')
  2. Check which CachePoolFactory classes are registered (io.mycat.cache package) and use exactly their type key, matching case
  3. Remove or comment out cache entries whose factory type is not available in your Mycat build
  4. If a custom cache type is intended, implement/verify the CachePoolFactory plugin is on the classpath and registered

Example fix

// before (cache config)
<cache name="sqlRouteCache" type="encache" ... />
// after
<cache name="sqlRouteCache" type="ehcache" ... />
Defensive patterns

Strategy: validation

Validate before calling

// before starting pools, validate cache types against available factories
Set<String> supported = CacheServiceProvider.loadFactories().stream()
    .map(CachePoolFactory::getName).collect(Collectors.toSet());
for (String type : configuredCacheTypes) {
    if (!supported.contains(type)) {
        throw new IllegalArgumentException("Unsupported cache type: " + type + ", supported: " + supported);
    }
}

Type guard

boolean isSupportedCacheType(String type) {
    return type != null && CacheService.getStaticCaps().keySet().contains(type);
}

Try / catch

try {
    CachePool pool = cacheService.getCachePool(poolName);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("CachePoolFactory not defined for type")) {
        LOG.error("Bad cache type in config: {}", e.getMessage());
        throw new ConfigurationException(e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: A cache name in the Mycat cache configuration (e.g. server.xml/ehcache section or cachecfg) declares a type string that does not match any registered CachePoolFactory key, so getCacheFact(type) finds no entry when layerdPool or cacheFact builds the pool.

Common situations: Typo in the cache type attribute; copying a cache config from another Mycat version where a factory type was renamed/removed; enabling a type like 'enjoyredis' or custom type without the matching plugin on the classpath; case-sensitivity mismatch ('Ehcache' vs 'ehcache').

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/0bbf82252226b42a. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/cache/CacheService.java:162

				factryClassName).newInstance();
		poolFactorys.put(factryType, factry);

	}

	private void createPool(String poolName, String type, int cacheSize,
			int expireSeconds) {
		checkExists(poolName);
		CachePoolFactory cacheFact = getCacheFact(type);
		CachePool cachePool = cacheFact.createCachePool(poolName, cacheSize,
				expireSeconds);
		allPools.put(poolName, cachePool);

	}

	private CachePoolFactory getCacheFact(String type) {
		CachePoolFactory facty = this.poolFactorys.get(type);
		if (facty == null) {
			throw new RuntimeException("CachePoolFactory not defined for type:"
					+ type);
		}
		return facty;
	}

	/**
	 * get cache pool by name ,caller should cache result
	 * 
	 * @param poolName
	 * @return CachePool
	 */
	public CachePool getCachePool(String poolName) {
		CachePool pool = allPools.get(poolName);
		if (pool == null) {
			throw new IllegalArgumentException("can't find cache pool:"
					+ poolName);
		} else {
			return pool;

View on GitHub (pinned to 65f8d8beb7)