当前位置: 首页>>代码示例>>Java>>正文


Java KeyGenerator类代码示例

本文整理汇总了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();  
        }  
    };  
  
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:RedisConfig.java

示例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();
		}
		
	};
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:21,代码来源:RedisConfiguration.java

示例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();
		}
	};
}
 
开发者ID:timebusker,项目名称:spring-boot-redis,代码行数:21,代码来源:RedisCacheConfig.java

示例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();  
         }  
     }; 
}
 
开发者ID:viakiba,项目名称:springboot,代码行数:17,代码来源:CacheRedisConfig.java

示例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();
		}
	};

}
 
开发者ID:lemon-china,项目名称:lemon-dubbo-message,代码行数:22,代码来源:RedisConfiguration.java

示例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();
		}
	};
}
 
开发者ID:xwjie,项目名称:ElementVueSpringbootCodeTemplate,代码行数:22,代码来源:RedisConfig.java

示例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();
        }

    };
}
 
开发者ID:Fourwenwen,项目名称:consistent-hashing-redis,代码行数:22,代码来源:CacheConfig.java

示例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();
		}
	};
}
 
开发者ID:profullstack,项目名称:spring-seed,代码行数:23,代码来源:SpringSeedRedis.java

示例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();
        }
    };

}
 
开发者ID:slking1987,项目名称:mafia,代码行数:17,代码来源:RedisConfig.java

示例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();
		}
	};
}
 
开发者ID:Myazure,项目名称:weixin_component,代码行数:17,代码来源:RedisConfiguration.java

示例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()]));

}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:KeyGeneratorAdapter.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AnnotationJCacheOperationSource.java

示例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();
     }
   };
 }
 
开发者ID:deib-polimi,项目名称:diceH2020-space4cloudsWS,代码行数:17,代码来源:Configurator.java

示例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;
        }
    };

}
 
开发者ID:fireshort,项目名称:spring-boot-quickstart,代码行数:19,代码来源:RedisConfig.java

示例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();

    };
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:12,代码来源:TxManagerConfiguration.java


注:本文中的org.springframework.cache.interceptor.KeyGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。