org.springframework.cache.annotation.CacheConfig Java Examples

The following examples show how to use org.springframework.cache.annotation.CacheConfig. 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: MyRedisCacheManager.java    From spring-boot-vue-admin with Apache License 2.0 5 votes vote down vote up
private void add(final Class clazz) {
  ReflectionUtils.doWithMethods(
      clazz,
      method -> {
        ReflectionUtils.makeAccessible(method);
        final CacheExpire cacheExpire = AnnotationUtils.findAnnotation(method, CacheExpire.class);
        if (cacheExpire == null) {
          return;
        }
        final Cacheable cacheable = AnnotationUtils.findAnnotation(method, Cacheable.class);
        if (cacheable != null) {
          this.add(cacheable.cacheNames(), cacheExpire);
          return;
        }
        final Caching caching = AnnotationUtils.findAnnotation(method, Caching.class);
        if (caching != null) {
          final Cacheable[] cs = caching.cacheable();
          if (cs.length > 0) {
            for (final Cacheable c : cs) {
              if (c != null) {
                this.add(c.cacheNames(), cacheExpire);
              }
            }
          }
        } else {
          final CacheConfig cacheConfig =
              AnnotationUtils.findAnnotation(clazz, CacheConfig.class);
          if (cacheConfig != null) {
            this.add(cacheConfig.cacheNames(), cacheExpire);
          }
        }
      },
      method -> null != AnnotationUtils.findAnnotation(method, CacheExpire.class));
}
 
Example #2
Source File: MyRedisCacheManager.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
private void add(final Class clazz) {
    ReflectionUtils.doWithMethods(clazz, method -> {
        ReflectionUtils.makeAccessible(method);
        CacheExpire cacheExpire = AnnotationUtils.findAnnotation(method, CacheExpire.class);
        if (cacheExpire == null) {
            return;
        }
        Cacheable cacheable = AnnotationUtils.findAnnotation(method, Cacheable.class);
        if (cacheable != null) {
            add(cacheable.cacheNames(), cacheExpire);
            return;
        }
        Caching caching = AnnotationUtils.findAnnotation(method, Caching.class);
        if (caching != null) {
            Cacheable[] cs = caching.cacheable();
            if (cs.length > 0) {
                for (Cacheable c : cs) {
                    if (cacheExpire != null && c != null) {
                        add(c.cacheNames(), cacheExpire);
                    }
                }
            }
        } else {
            CacheConfig cacheConfig = AnnotationUtils.findAnnotation(clazz, CacheConfig.class);
            if (cacheConfig != null) {
                add(cacheConfig.cacheNames(), cacheExpire);
            }
        }
    }, method -> null != AnnotationUtils.findAnnotation(method, CacheExpire.class));
}
 
Example #3
Source File: CacheKeyGenerator.java    From bird-java with MIT License 5 votes vote down vote up
@Override
public Object generate(Object target, Method method, Object... params) {
    Class<?> cls = target.getClass();
    String cachePrefix = Constant.Cache.CLASSKEY_MAP.get(cls);
    if (StringUtils.isBlank(cachePrefix)) {
        CacheConfig cacheConfig = cls.getAnnotation(CacheConfig.class);
        if (cacheConfig == null || ArrayUtils.isEmpty(cacheConfig.cacheNames())) {
            cachePrefix = cls.getName();
        } else {
            cachePrefix = cacheConfig.cacheNames()[0];
        }
        Constant.Cache.CLASSKEY_MAP.put(cls, cachePrefix);
    }

    String cacheName;
    Cacheable cacheable = method.getAnnotation(Cacheable.class);
    CachePut cachePut = method.getAnnotation(CachePut.class);
    CacheEvict cacheEvict = method.getAnnotation(CacheEvict.class);

    if (cacheable != null && ArrayUtils.isNotEmpty(cacheable.value())) {
        cacheName = cacheable.value()[0];
    } else if (cachePut != null && ArrayUtils.isNotEmpty(cachePut.value())) {
        cacheName = cachePut.value()[0];
    } else if (cacheEvict != null && ArrayUtils.isNotEmpty(cacheEvict.value())) {
        cacheName = cacheEvict.value()[0];
    } else {
        cacheName = method.getName();
    }

    return cachePrefix + ":" + cacheName + ":" + generateKey(params);
}
 
Example #4
Source File: SpringRedisCacheManager.java    From Mykit with Apache License 2.0 4 votes vote down vote up
private Set<String> findCacheNames(CacheConfig cacheConfig, Cacheable cacheable) {
    return isEmpty(cacheable.value()) ? new HashSet(Arrays.asList(cacheConfig.cacheNames())) : new HashSet(Arrays.asList(cacheable.value()));
}