I am using Spring-boot + Redis to store my data on cache.
My Controller has this configuration:
public class CacheController {
@GetMapping("/{key}")
@Cacheable(value = "myCacheValue", keyGenerator = "customKeyGenerator")
public String getByKey(@PathVariable("key") String key) {
return key + System.currentTimeMillis();
}
}
My customKeyGenerator is:
public class CustomKeyGenerator implements KeyGenerator {
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getSimpleName())
.append("-")
.append(method.getName());
if (params != null) {
for (Object param : params) {
sb.append("-")
.append(param.getClass().getSimpleName())
.append(":").append(param);
}
}
return sb.toString();
}
}
When I connect in my redis I have this key:
1 - redis-cli --raw
KEYS *
myCacheValue~keys
��t$CacheController-getByKey-String:key9
2 - redis-cli
KEYS *
myCacheValue~keys
\xac\xed\x00\x05t\x00$CacheController-getByKey-String:key9
Why this characters are present before "CacheController"?
Note: My key Generator starts with my Class name.
I would like that my key name be only this: CacheController-getByKey-String:myKey