private void addCacheExpires(final Class clazz, final Map<String, Long> cacheExpires) { ReflectionUtils.doWithMethods(clazz, method -> { ReflectionUtils.makeAccessible(method); CacheDuration cacheDuration = findCacheDuration(clazz, method); Cacheable cacheable = findAnnotation(method, Cacheable.class); CacheConfig cacheConfig = findAnnotation(clazz, CacheConfig.class); Set<String> cacheNames = findCacheNames(cacheConfig, cacheable); for (String cacheName : cacheNames) { if (cacheDuration != null) { cacheExpires.put(cacheName, cacheDuration.expireSeconds()); } } }, method -> null != findAnnotation(method, Cacheable.class)); }
/** * @return */ private String getCacheKey() { Class<?> cls = getClass(); String cacheName = Constants.cacheKeyMap.get(cls); if (StringUtils.isBlank(cacheName)) { CacheConfig cacheConfig = cls.getAnnotation(CacheConfig.class); if (cacheConfig != null && ArrayUtils.isNotEmpty(cacheConfig.cacheNames())) { cacheName = cacheConfig.cacheNames()[0]; } else { cacheName = getClass().getName(); } Constants.cacheKeyMap.put(cls, cacheName); } return cacheName; }
/** * @return */ private String getCacheKey() { Class<?> cls = getClass(); String cacheName = Constants.cacheKeyMap.get(cls); if (StringUtils.isBlank(cacheName)) { CacheConfig cacheConfig = cls.getAnnotation(CacheConfig.class); if (cacheConfig == null || cacheConfig.cacheNames() == null || cacheConfig.cacheNames().length < 1) { cacheName = getClass().getName(); } else { cacheName = cacheConfig.cacheNames()[0]; } Constants.cacheKeyMap.put(cls, cacheName); } return cacheName; }
/** 获取缓存键值 */ protected String getCacheKey(Object id) { String cacheName = null; CacheConfig cacheConfig = getClass().getAnnotation(CacheConfig.class); if (cacheConfig == null || cacheConfig.cacheNames() == null || cacheConfig.cacheNames().length < 1) { cacheName = getClass().getName(); } else { cacheName = cacheConfig.cacheNames()[0]; } return new StringBuilder(Constants.CACHE_NAMESPACE).append(cacheName).append(":").append(id).toString(); }
private HashSet<String> findCacheNames(CacheConfig cacheConfig, Cacheable cacheable) { return cacheable.value().length == 0 ? new HashSet<>(Arrays.asList(cacheConfig.cacheNames())) : new HashSet<>(Arrays.asList(cacheable.value())); }