com.soento.redis.support.GenericKeyGenerator Maven / Gradle / Ivy
package com.soento.redis.support;
import com.soento.core.util.StringUtil;
import org.springframework.cache.interceptor.KeyGenerator;
import java.lang.reflect.Method;
/**
* @author soento
*/
public class GenericKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder key = new StringBuilder();
key.append(target.getClass().getName());
key.append(".");
key.append(method.getName());
key.append("(");
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
key.append(StringUtil.toString(params[i]).replaceAll(":", "="));
if (i != params.length - 1) {
key.append(", ");
}
}
}
key.append(")");
return key.toString();
}
}