{"record":{"id":"ab416af10d44939b","repo":"apache/cassandra","slug":"setting-capacity-of-nopcache-is-not-permitted-as-t","errorCode":null,"errorMessage":"Setting capacity of NopCache is not permitted as this cache is disabled. Check your yaml settings if you want to enable it.","messagePattern":"Setting capacity of NopCache is not permitted as this cache is disabled\\. Check your yaml settings if you want to enable it\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cache/NopCacheProvider.java","lineNumber":41,"sourceCode":"public class NopCacheProvider implements CacheProvider<RowCacheKey, IRowCacheEntry>\n{\n    public ICache<RowCacheKey, IRowCacheEntry> create()\n    {\n        return new NopCache();\n    }\n\n    private static class NopCache implements ICache<RowCacheKey, IRowCacheEntry>\n    {\n        public long capacity()\n        {\n            return 0;\n        }\n\n        public void setCapacity(long capacity)\n        {\n            if (capacity != 0)\n            {\n                throw new UnsupportedOperationException(\"Setting capacity of \" + NopCache.class.getSimpleName()\n                                                        + \" is not permitted as this cache is disabled. Check your yaml settings if you want to enable it.\");\n            }\n        }\n\n        public void put(RowCacheKey key, IRowCacheEntry value)\n        {\n        }\n\n        public boolean putIfAbsent(RowCacheKey key, IRowCacheEntry value)\n        {\n            return false;\n        }\n\n        public boolean replace(RowCacheKey key, IRowCacheEntry old, IRowCacheEntry value)\n        {\n            return false;\n        }\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cache/NopCacheProvider.java#L23-L59","documentation":"NopCache is a disabled no-op cache; it intentionally performs nothing and must never be given a nonzero capacity, since that would imply it caches data it does not store. setCapacity throws UnsupportedOperationException for any nonzero value; passing 0 is accepted silently. The message points at yaml settings because this cache is selected when the corresponding cache type is disabled in config.","triggerScenarios":"Calling NopCache.setCapacity(c) with c != 0, typically via JMX CacheService mbeans or code that resizes caches at runtime (e.g. CacheService.setRowCacheCapacity), or when a user enables capacity in cassandra.yaml while the cache implementation resolved to NopCache.","commonSituations":"Operators increasing row/key cache size via JMX (nodetool setcachecapacity paths) on a node where that cache is disabled in cassandra.yaml; misconfigured yaml that disables a cache but still sets its max size; automated tuning scripts applying capacity to all caches.","solutions":["If you actually want the cache, enable it in cassandra.yaml (e.g. row_cache_size_in_mb > 0 and the correct cache implementation) and restart the node so a real cache (SerializingCache) is created instead of NopCache.","If the cache is intentionally disabled, call setCapacity(0) or do not call it at all.","In generic code that resizes caches, catch UnsupportedOperationException or skip caches that are disabled.","Check yaml keys such as row_cache_size_in_mb / key_cache_size_in_mb match the enabled cache types."],"exampleFix":"// before\ncacheService.setRowCacheCapacity(rowCacheSizeInMb); // throws when row cache is disabled (NopCache)\n// after\n// cassandra.yaml: enable the cache first\n// row_cache_size_in_mb: 256\n// then restart the node and resize at runtime","handlingStrategy":"validation","validationCode":"// before resizing, confirm the cache is actually enabled\nif (cache instanceof org.apache.cassandra.cache.NopCache && capacity != 0) {\n    throw new IllegalStateException(\"Cache disabled in yaml; enable it in cassandra.yaml before resizing\");\n}","typeGuard":"boolean isCacheEnabled(ICache<?,?> c) { return !(c instanceof org.apache.cassandra.cache.NopCache); }","tryCatchPattern":"try {\n    cache.setCapacity(capacity);\n} catch (UnsupportedOperationException e) {\n    logger.warn(\"Cache disabled: {}\", e.getMessage()); // enable in yaml + restart\n}","preventionTips":["Enable the cache in cassandra.yaml before attempting runtime resize.","Pass 0 (or skip the call) when the cache is intentionally disabled.","Check NopCacheProvider/NopCache type before generic resize loops.","Keep yaml cache sizes consistent with enabled cache types."],"tags":["cache","unsupported-operation","configuration"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}