This is an automated email from the ASF dual-hosted git repository.

adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 91da34a8c6 FINERACT-2262: Fix cache resolution
91da34a8c6 is described below

commit 91da34a8c644357c72aafbf788bad7fc12459e17
Author: Adam Saghy <[email protected]>
AuthorDate: Tue May 20 15:33:15 2025 +0200

    FINERACT-2262: Fix cache resolution
---
 .../infrastructure/core/config/cache/CacheConfig.java     | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/cache/CacheConfig.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/cache/CacheConfig.java
index f64c947a99..b9196a3d95 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/cache/CacheConfig.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/cache/CacheConfig.java
@@ -80,13 +80,24 @@ public class CacheConfig {
         javax.cache.configuration.Configuration<Object, Object> 
defaultTemplate = generateCacheConfiguration(defaultMaxEntries,
                 defaultTimeToLive);
         // Scan all packages (entire classpath)
-        Reflections reflections = new Reflections(
-                new 
ConfigurationBuilder().setUrls(ClasspathHelper.forJavaClassPath()).addScanners(Scanners.MethodsAnnotated));
+        Reflections reflections = new Reflections(new 
ConfigurationBuilder().setUrls(ClasspathHelper.forJavaClassPath())
+                .addScanners(Scanners.MethodsAnnotated, 
Scanners.TypesAnnotated));
         // Find all methods annotated with @Cacheable
         Set<Method> annotatedMethods = 
reflections.getMethodsAnnotatedWith(Cacheable.class);
         Set<String> cacheNames = annotatedMethods.stream().map(method -> 
method.getAnnotation(Cacheable.class))
                 .flatMap(annotation -> 
Stream.concat(Arrays.stream(annotation.value()), 
Arrays.stream(annotation.cacheNames())))
                 .collect(Collectors.toSet());
+        // Find all types annotated with @Cacheable
+        Set<Class<?>> annotatedClasses = 
reflections.getTypesAnnotatedWith(Cacheable.class);
+        cacheNames.addAll(annotatedClasses.stream().map(clazz -> 
clazz.getAnnotation(Cacheable.class))
+                .flatMap(annotation -> 
Stream.concat(Arrays.stream(annotation.value()), 
Arrays.stream(annotation.cacheNames())))
+                .collect(Collectors.toSet()));
+        // Find all types annotated with @CacheConfig
+        Set<Class<?>> annotatedCacheConfigClasses = reflections
+                
.getTypesAnnotatedWith(org.springframework.cache.annotation.CacheConfig.class);
+        cacheNames.addAll(annotatedCacheConfigClasses.stream()
+                .map(clazz -> 
clazz.getAnnotation(org.springframework.cache.annotation.CacheConfig.class))
+                .flatMap(annotation -> 
Arrays.stream(annotation.cacheNames())).collect(Collectors.toSet()));
         // Register the caches into the cache manager
         cacheNames.forEach(cacheName -> {
             if (cacheManager.getCache(cacheName) == null) {

Reply via email to