{"record":{"id":"87c8986a2f7d945b","repo":"redis/jedis","slug":"cache-is-required-to-build-cacheconnection","errorCode":null,"errorMessage":"Cache is required to build CacheConnection.","messagePattern":"Cache is required to build CacheConnection\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/csc/CacheConnection.java","lineNumber":57,"sourceCode":"    @Override\n    public Builder clientConfig(JedisClientConfig clientConfig) {\n      super.clientConfig(clientConfig);\n      return this;\n    }\n\n    @Override\n    protected Connection createConnection() {\n      return new CacheConnection(this);\n    }\n  }\n\n  public static Builder builder(Cache cache) {\n    return new Builder(cache);\n  }\n\n  @VisibleForTesting\n  public static Builder builder() {\n    throw new UnsupportedOperationException(\"Cache is required to build CacheConnection.\");\n  }\n\n  private final Cache cache;\n  private ReentrantLock lock;\n  private static final String REDIS = \"redis\";\n  private static final String MIN_REDIS_VERSION = \"7.4\";\n\n  public CacheConnection(final JedisSocketFactory socketFactory, JedisClientConfig clientConfig, Cache cache) {\n    super(socketFactory, clientConfig);\n\n    this.cache = Objects.requireNonNull(cache);\n    initializeClientSideCache();\n  }\n\n  private CacheConnection(Builder builder) {\n    super(builder);\n    this.cache = builder.getCache();\n  }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/csc/CacheConnection.java#L39-L75","documentation":"The no-arg CacheConnection.builder() overload is intentionally disabled: client-side caching fundamentally needs a Cache to receive invalidation pushes, so calling it always throws UnsupportedOperationException. It exists only for testing/framework symmetry with other Connection types (@VisibleForTesting). Production code must use the builder(Cache) overload.","triggerScenarios":"Calling CacheConnection.builder() with no arguments anywhere in application code; generic connection-building frameworks that reflectively invoke a no-arg builder() method for all connection types.","commonSituations":"Migrating code that built other connection types (e.g. DefaultJedisSocketFactory-based connections) with a parameterless builder and reusing the same pattern; a factory using reflection/strategy to call builder() uniformly across connection implementations.","solutions":["Switch to CacheConnection.builder(cache), supplying a Cache built via CacheFactory.getCache(cacheConfig).","If your generic builder framework calls no-arg builder(), special-case CacheConnection to invoke builder(cache) instead.","Treat the exception as a signal that client-side caching cannot be used without a cache; if you do not need caching, use a plain connection type."],"exampleFix":"// before\nCacheConnection.Builder b = CacheConnection.builder(); // always throws\n// after\nCache cache = CacheFactory.getCache(new CacheConfig());\nCacheConnection.Builder b = CacheConnection.builder(cache);","handlingStrategy":"validation","validationCode":"if (cache == null) { throw new UnsupportedOperationException(\"Use CacheConnection.builder(cache) — client-side caching requires a Cache\"); }\nCacheConnection connection = CacheConnection.builder(cache);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only the builder(Cache) overload; treat builder() as test-only","In generic reflective builders, special-case CacheConnection to pass a cache","Do not use CacheConnection at all if client-side caching is not needed"],"tags":["unsupported-operation","client-side-caching","builder"],"backgroundTag":"unsupported-operation","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"}