{"record":{"id":"196d7b9b457ba714","repo":"redis/jedis","slug":"cacheable-is-required-to-create-the-default-cache","errorCode":null,"errorMessage":"Cacheable is required to create the default cache!","messagePattern":"Cacheable is required to create the default cache!","errorType":"validation","errorClass":"JedisCacheException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/csc/CacheFactory.java","lineNumber":14,"sourceCode":"package redis.clients.jedis.csc;\n\nimport java.lang.reflect.Constructor;\nimport java.lang.reflect.InvocationTargetException;\nimport java.util.Arrays;\n\nimport redis.clients.jedis.exceptions.JedisCacheException;\n\npublic final class CacheFactory {\n\n    public static Cache getCache(CacheConfig config) {\n        if (config.getCacheClass() == null) {\n            if (config.getCacheable() == null) {\n                throw new JedisCacheException(\"Cacheable is required to create the default cache!\");\n            }\n            return new DefaultCache(config.getMaxSize(), config.getCacheable(), getEvictionPolicy(config));\n        }\n        return instantiateCustomCache(config);\n    }\n\n    private static Cache instantiateCustomCache(CacheConfig config) {\n        try {\n            if (config.getCacheable() != null) {\n                Constructor ctorWithCacheable = findConstructorWithCacheable(config.getCacheClass());\n                if (ctorWithCacheable != null) {\n                    return (Cache) ctorWithCacheable.newInstance(config.getMaxSize(), getEvictionPolicy(config), config.getCacheable());\n                }\n            }\n            Constructor ctor = getConstructor(config.getCacheClass());\n            return (Cache) ctor.newInstance(config.getMaxSize(), getEvictionPolicy(config));\n        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException\n                | SecurityException e) {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/csc/CacheFactory.java#L1-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set a Cacheable on the config: config.setCacheable(new CacheableString()) or your own Cacheable implementation.","Alternatively set a custom cache class via config.setCacheClass(MyCache.class) so the default-cache path is skipped.","Validate the CacheConfig (cacheClass or cacheable present) before calling CacheFactory.getCache."],"exampleFix":"// before\nCacheConfig config = new CacheConfig();\nconfig.setMaxSize(1000);\nCache cache = CacheFactory.getCache(config); // throws\n// after\nCacheConfig config = new CacheConfig();\nconfig.setMaxSize(1000);\nconfig.setCacheable(new CacheableString());\nCache cache = CacheFactory.getCache(config);","handlingStrategy":"validation","validationCode":"CacheConfig config = ...;\nif (config.getCacheClass() == null && config.getCacheable() == null) {\n  config.setCacheable(new CacheableString()); // or require it explicitly\n}\nCache cache = CacheFactory.getCache(config);","typeGuard":null,"tryCatchPattern":"try {\n  Cache cache = CacheFactory.getCache(config);\n} catch (JedisCacheException e) {\n  if (e.getMessage().contains(\"Cacheable is required\")) {\n    config.setCacheable(new CacheableString());\n    Cache cache = CacheFactory.getCache(config);\n  } else throw e;\n}","preventionTips":["Always call setCacheable(...) or setCacheClass(...) on CacheConfig before getCache","Load CacheConfig from files with a schema check that fails fast on missing cacheable/cacheClass","Copy full examples, not trimmed ones, when adopting CacheConfig"],"tags":["cache-config","missing-required-config","client-side-caching"],"backgroundTag":"missing-required-config-field","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}