當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。