{"record":{"id":"a9c42b436570654d","repo":"Tencent/APIJSON","slug":"cache-value-value-0-1-2-all-rom","errorCode":null,"errorMessage":"@cache:value 中 value 的值不合法！必须在 [0,1,2] 或 [ALL, ROM, RAM] 内 !","messagePattern":"@cache:value 中 value 的值不合法！必须在 \\[0,1,2\\] 或 \\[ALL, ROM, RAM\\] 内 !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java","lineNumber":3033,"sourceCode":"\t\t\t//\t\t\tif (isSubquery) {\n\t\t\t//\t\t\t\tthrow new IllegalArgumentException(\"子查询内不支持传 \" + apijson.JSONMap.KEY_CACHE + \"!\");\n\t\t\t//\t\t\t}\n\n\t\t\tswitch (cache) {\n\t\t\tcase \"0\":\n\t\t\tcase JSONMap.CACHE_ALL_STRING:\n\t\t\t\tcache2 = JSONMap.CACHE_ALL;\n\t\t\t\tbreak;\n\t\t\tcase \"1\":\n\t\t\tcase JSONMap.CACHE_ROM_STRING:\n\t\t\t\tcache2 = JSONMap.CACHE_ROM;\n\t\t\t\tbreak;\n\t\t\tcase \"2\":\n\t\t\tcase JSONMap.CACHE_RAM_STRING:\n\t\t\t\tcache2 = JSONMap.CACHE_RAM;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new IllegalArgumentException(JSONMap.KEY_CACHE\n\t\t\t\t\t\t+ \":value 中 value 的值不合法！必须在 [0,1,2] 或 [ALL, ROM, RAM] 内 !\");\n\t\t\t}\n\t\t}\n\t\treturn cache2;\n\t}\n\n\t@Override\n\tpublic boolean isExplain() {\n\t\treturn explain;\n\t}\n\t@Override\n\tpublic AbstractSQLConfig<T, M, L> setExplain(boolean explain) {\n\t\tthis.explain = explain;\n\t\treturn this;\n\t}\n\n\t@Override\n\tpublic List<Join<T, M, L>> getJoinList() {","sourceCodeStart":3015,"sourceCodeEnd":3051,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L3015-L3051","documentation":"getCache() maps the @cache value to an int via a switch; only 0/1/2 and ALL/ROM/RAM (case-sensitive, JSONMap.CACHE_*_STRING constants) are accepted. Any other string hits the default branch and throws IllegalArgumentException. @cache controls whether query results may be served from or stored in the all/rom/ram cache layer.","triggerScenarios":"A request like {\"@cache\":\"ram\", \"User\":{...}} (lowercase), {\"@cache\":3}, {\"@cache\":\" ROM \"}, or {\"@cache\":true}. The switch is over strings, so numeric values other than \"0\"/\"1\"/\"2\" and any whitespace/case variant of ALL/ROM/RAM fail.","commonSituations":"Assuming @cache is case-insensitive; passing a boolean because other APIJSON flags accept true/false; trailing whitespace from template-built request JSON; version drift where older docs listed different cache keywords.","solutions":["Use exactly 0|1|2 or ALL|ROM|RAM, uppercase, no whitespace: {\"@cache\":\"RAM\"}.","If the value comes from user input or config, normalize it (trim + toUpperCase) and check membership before sending the request.","Default to omitting @cache entirely when caching is not needed — the field is optional."],"exampleFix":"// before\n{\"@cache\":\"ram\",\"User\":{\"id\":1}}\n// after\n{\"@cache\":\"RAM\",\"User\":{\"id\":1}}","handlingStrategy":"validation","validationCode":"Set<String> CACHE = Set.of(\"0\",\"1\",\"2\",\"ALL\",\"ROM\",\"RAM\");\nString v = String.valueOf(request.get(\"@cache\")).strip().toUpperCase();\nif (!CACHE.contains(v)) request.put(\"@cache\", \"ALL\"); // or reject","typeGuard":"function isValidCache(v: unknown): v is string {\n  return [\"0\",\"1\",\"2\",\"ALL\",\"ROM\",\"RAM\"].includes(String(v).trim().toUpperCase());\n}","tryCatchPattern":null,"preventionTips":["Centralize @cache values as an enum/constant set in your client code.","Normalize case and trim whitespace before injecting into request JSON.","Omit @cache when caching is not needed."],"tags":["apijson","cache","request-argument","enum-validation"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}