com.feingto.cloud.config.redis.support.CacheUtils Maven / Gradle / Ivy
The newest version!
package com.feingto.cloud.config.redis.support;
import com.feingto.cloud.config.annotation.ApplicationContextHold;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* 缓存工具类
*
* @author longfei
*/
public class CacheUtils {
/**
* Generate a name for the given method and its parameters.
*
* @param target the target instance
* @return a generated name
*/
public static String generateName(Object target) {
return Optional.ofNullable(ApplicationContextHold.getBean(Environment.class))
.map(env -> Binder.get(env).bind("spring.application.name", String.class)
.orElse(null))
.orElse("application")
.concat(":")
.concat(target.getClass().getName());
}
/**
* Generate a key for the given method and its parameters.
*
* @param method the method being called
* @param params the method parameters (with any var-args expanded)
* @return a generated key
*/
public static String generateKey(Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(method.getName());
for (Object obj : params) {
sb.append(":").append(obj.toString());
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy