本文整理匯總了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();
};
}