本文整理汇总了Java中org.springframework.cache.interceptor.KeyGenerator类的典型用法代码示例。如果您正苦于以下问题:Java KeyGenerator类的具体用法?Java KeyGenerator怎么用?Java KeyGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyGenerator类属于org.springframework.cache.interceptor包,在下文中一共展示了KeyGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean
public KeyGenerator customKeyGenerator(){
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
示例2: keyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Override
public KeyGenerator keyGenerator() {
return new KeyGenerator(){
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
//添加类名
sb.append(target.getClass().getName());
sb.append(":");
//添加方法名
sb.append(method.getName());
for(Object o : params){
sb.append(":");
sb.append(o.toString());
}
return sb.toString();
}
};
}
示例3: keyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
/**
* 自定义key. 此方法将会根据类名+方法名+所有参数的值生成唯一的一个key,即使@Cacheable中的value属性一样,key也会不一样。
*/
@Override
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object o, Method method, Object... objects) {
// This will generate a unique key of the class name, the method name and all method parameters appended.
StringBuilder buffer = new StringBuilder();
buffer.append(o.getClass().hashCode());
buffer.append(method.getName());
for (Object obj : objects) {
buffer.append(obj.toString());
}
System.out.println("keyGenerator=" + buffer.toString());
return buffer.toString();
}
};
}
示例4: getKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean(name = "SimpleKey")
public KeyGenerator getKeyGenerator(){
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
System.out.println(sb.toString());
return sb.toString();
}
};
}
示例5: lemonKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean
public KeyGenerator lemonKeyGenerator() {
return new KeyGenerator() {
//key格式 className:methodName:value1:value2
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(":");
sb.append(method.getName());
for (Object obj : params) {
if (obj!=null) {
sb.append(":");
sb.append(obj.toString());
}
}
return sb.toString();
}
};
}
示例6: keyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Override
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getSimpleName());
sb.append('.').append(method.getName());
// FIXME 参数太长的时候请指定key属性,否则key太长
for (Object obj : params) {
if (obj != null) {
sb.append(obj.toString());
}
}
return sb.toString();
}
};
}
示例7: wiselyKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
/**
* key的生成器
*
* @return
*/
@Bean
public KeyGenerator wiselyKeyGenerator() {
return new KeyGenerator() {
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
示例8: keyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
/**
* this was used to generate unique key for each method, the key will be like:
* className + methodName + args.
*/
@Bean
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(":");
sb.append(method.getName());
sb.append(":");
for (Object obj : params) {
sb.append(String.valueOf(obj));
sb.append(":");
}
return sb.toString();
}
};
}
示例9: wiselyKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean(name = "wiselyKeyGenerator")
public KeyGenerator wiselyKeyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
示例10: wiselyKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean
public KeyGenerator wiselyKeyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method,
Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
示例11: doGenerate
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) {
List<Object> parameters = new ArrayList<Object>();
for (CacheInvocationParameter param : context.getKeyParameters()) {
Object value = param.getValue();
if (param.getParameterPosition() == context.getAllParameters().length - 1 &&
context.getMethod().isVarArgs()) {
parameters.addAll((List<Object>) CollectionUtils.arrayToList(value));
}
else {
parameters.add(value);
}
}
return keyGenerator.generate(context.getTarget(), context.getMethod(),
parameters.toArray(new Object[parameters.size()]));
}
示例12: createCacheResultOperation
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
protected CacheResultOperation createCacheResultOperation(Method method, CacheDefaults defaults, CacheResult ann) {
String cacheName = determineCacheName(method, defaults, ann.cacheName());
CacheResolverFactory cacheResolverFactory =
determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);
CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
CacheResolver exceptionCacheResolver = null;
final String exceptionCacheName = ann.exceptionCacheName();
if (StringUtils.hasText(exceptionCacheName)) {
exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
}
return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
示例13: spjKeyGen
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean(name=SPJ_KEYGENERATOR)
public KeyGenerator spjKeyGen() {
return new KeyGenerator() {
@Override
public Object generate(Object o, Method method, Object... objects) {
StringBuilder sb = new StringBuilder();
sb.append(o.getClass().getName());
sb.append(method.getName());
for (Object obj : objects) {
sb.append(obj.toString());
}
return sb.toString();
}
};
}
示例14: wiselyKeyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean
public KeyGenerator wiselyKeyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
for (Object obj : params) {
sb.append(obj.toString());
}
String key = sb.toString();
logger.info("key:" + key);
return key;
}
};
}
示例15: keyGenerator
import org.springframework.cache.interceptor.KeyGenerator; //导入依赖的package包/类
@Bean
public KeyGenerator keyGenerator() {
return (target, method, params) -> {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(method.getName());
return Arrays.stream(params)
.map(obj -> sb.append(obj.toString())).toString();
};
}