Java Code Examples for org.springframework.cache.interceptor.KeyGenerator#generate()

The following examples show how to use org.springframework.cache.interceptor.KeyGenerator#generate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyGeneratorAdapter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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()]));

}
 
Example 2
Source File: KeyGeneratorAdapter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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()]));

}
 
Example 3
Source File: KeyGeneratorAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) {
	List<Object> parameters = new ArrayList<>();
	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());
}
 
Example 4
Source File: AbstractKeyCacheInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Generate a key for the specified invocation.
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
	KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
	Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
	if (logger.isTraceEnabled()) {
		logger.trace("Computed cache key " + key + " for operation " + context.getOperation());
	}
	return key;
}
 
Example 5
Source File: KeyGeneratorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) {
	List<Object> parameters = new ArrayList<>();
	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());
}
 
Example 6
Source File: AbstractKeyCacheInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Generate a key for the specified invocation.
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
	KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
	Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
	if (logger.isTraceEnabled()) {
		logger.trace("Computed cache key " + key + " for operation " + context.getOperation());
	}
	return key;
}
 
Example 7
Source File: AbstractKeyCacheInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a key for the specified invocation.
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
	KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
	Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
	if (logger.isTraceEnabled()) {
		logger.trace("Computed cache key " + key + " for operation " + context.getOperation());
	}
	return key;
}
 
Example 8
Source File: AbstractKeyCacheInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a key for the specified invocation.
 * @param context the context of the invocation
 * @return the key to use
 */
protected Object generateKey(CacheOperationInvocationContext<O> context) {
	KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
	Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
	if (logger.isTraceEnabled()) {
		logger.trace("Computed cache key " + key + " for operation " + context.getOperation());
	}
	return key;
}