redis/jedis · error · JedisCacheException

Cacheable is required to create the default cache!

Error message

Cacheable is required to create the default cache!

What it means

CacheFactory.getCache builds a DefaultCache when no custom CacheClass is configured; DefaultCache requires a Cacheable (its serialization/eviction helper), so if neither a cache class nor a cacheable is set, a JedisCacheException is thrown. This is a configuration-completeness check: you must either point at a custom cache class or supply a Cacheable for the default cache.

Solutions

  1. Set a Cacheable on the config: config.setCacheable(new CacheableString()) or your own Cacheable implementation.
  2. Alternatively set a custom cache class via config.setCacheClass(MyCache.class) so the default-cache path is skipped.
  3. Validate the CacheConfig (cacheClass or cacheable present) before calling CacheFactory.getCache.

Example fix

// before
CacheConfig config = new CacheConfig();
config.setMaxSize(1000);
Cache cache = CacheFactory.getCache(config); // throws
// after
CacheConfig config = new CacheConfig();
config.setMaxSize(1000);
config.setCacheable(new CacheableString());
Cache cache = CacheFactory.getCache(config);
Defensive patterns

Strategy: validation

Validate before calling

CacheConfig config = ...;
if (config.getCacheClass() == null && config.getCacheable() == null) {
  config.setCacheable(new CacheableString()); // or require it explicitly
}
Cache cache = CacheFactory.getCache(config);

Try / catch

try {
  Cache cache = CacheFactory.getCache(config);
} catch (JedisCacheException e) {
  if (e.getMessage().contains("Cacheable is required")) {
    config.setCacheable(new CacheableString());
    Cache cache = CacheFactory.getCache(config);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling CacheFactory.getCache(config) where CacheConfig has getCacheClass() == null and getCacheable() == null — i.e. a fresh CacheConfig() with only (or no) maxSize set and no setCacheable(...) call.

Common situations: Building CacheConfig from properties/config files where the cacheable field was omitted; copying examples that used a custom cache class and removing it without adding a Cacheable; early bootstrap code calling getCache before cacheable wiring completes.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/196d7b9b457ba714. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/csc/CacheFactory.java:14

package redis.clients.jedis.csc;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

import redis.clients.jedis.exceptions.JedisCacheException;

public final class CacheFactory {

    public static Cache getCache(CacheConfig config) {
        if (config.getCacheClass() == null) {
            if (config.getCacheable() == null) {
                throw new JedisCacheException("Cacheable is required to create the default cache!");
            }
            return new DefaultCache(config.getMaxSize(), config.getCacheable(), getEvictionPolicy(config));
        }
        return instantiateCustomCache(config);
    }

    private static Cache instantiateCustomCache(CacheConfig config) {
        try {
            if (config.getCacheable() != null) {
                Constructor ctorWithCacheable = findConstructorWithCacheable(config.getCacheClass());
                if (ctorWithCacheable != null) {
                    return (Cache) ctorWithCacheable.newInstance(config.getMaxSize(), getEvictionPolicy(config), config.getCacheable());
                }
            }
            Constructor ctor = getConstructor(config.getCacheClass());
            return (Cache) ctor.newInstance(config.getMaxSize(), getEvictionPolicy(config));
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
                | SecurityException e) {

View on GitHub (pinned to 6dac31d4c2)