Example usage for org.springframework.cache.interceptor KeyGenerator generate

List of usage examples for org.springframework.cache.interceptor KeyGenerator generate

Introduction

In this page you can find the example usage for org.springframework.cache.interceptor KeyGenerator generate.

Prototype

Object generate(Object target, Method method, Object... params);

Source Link

Document

Generate a key for the given method and its parameters.

Usage

From source file:springfox.documentation.spring.web.caching.CachingAspect.java

@Around("(operationRead() || propertiesFor()) && @annotation(cacheable)")
public Object operationsAndProperties(ProceedingJoinPoint joinPoint, Cacheable cacheable) throws Throwable {
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    KeyGenerator keyGenerator = cacheable.keyGenerator().newInstance();
    Object key = keyGenerator.generate(joinPoint.getTarget(), method, joinPoint.getArgs());
    LOG.info("Caching aspect applied for cache {} with key {}", cacheable.value(), key);
    return cachedValue(joinPoint, cacheable.value(), key);
}

From source file:springfox.documentation.spring.web.caching.CachingAspect.java

@Around("(model() || dependenciesFor()) && @annotation(cacheable)")
public Object modelsAndDependencies(ProceedingJoinPoint joinPoint, Cacheable cacheable) throws Throwable {

    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    KeyGenerator keyGenerator = cacheable.keyGenerator().getDeclaredConstructor(TypeResolver.class)
            .newInstance(typeResolver);/*from  w w  w  .ja  va2s . co  m*/
    Object key = keyGenerator.generate(joinPoint.getTarget(), method, joinPoint.getArgs());
    LOG.info("Caching aspect applied for cache {} with key {}", cacheable.value(), key);
    return cachedValue(joinPoint, cacheable.value(), key);
}