vidakovic commented on code in PR #3041:
URL: https://github.com/apache/fineract/pull/3041#discussion_r1135122051


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/service/RuntimeDelegatingCacheManager.java:
##########
@@ -43,92 +43,82 @@
  * database on startup and allow user to switch implementation through UI/API
  */
 @Component(value = "runtimeDelegatingCacheManager")
-public class RuntimeDelegatingCacheManager implements CacheManager {
-
-    private static final Logger LOG = 
LoggerFactory.getLogger(RuntimeDelegatingCacheManager.class);
-
-    private final CacheManager cacheManager;
-    private final CacheManager noOpCacheManager = new NoOpCacheManager();
+@RequiredArgsConstructor
+@Slf4j
+public class RuntimeDelegatingCacheManager implements CacheManager, 
InitializingBean {
+
+    @Qualifier("ehCacheManager")
+    private final CacheManager ehCacheManager;
+    @Qualifier("defaultCacheManager")
+    private final CacheManager defaultCacheManager;
     private CacheManager currentCacheManager;
 
-    @Autowired
-    public RuntimeDelegatingCacheManager(final JCacheCacheManager 
cacheManager) {
-        this.cacheManager = cacheManager;
-        this.currentCacheManager = this.noOpCacheManager;
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        currentCacheManager = defaultCacheManager;
     }
 
     @Override
     public Cache getCache(final String name) {
-        return this.currentCacheManager.getCache(name);
+        return currentCacheManager.getCache(name);
     }
 
     @Override
     public Collection<String> getCacheNames() {
-        return this.currentCacheManager.getCacheNames();
+        return currentCacheManager.getCacheNames();
     }
 
     public Collection<CacheData> retrieveAll() {
 
-        final boolean noCacheEnabled = this.currentCacheManager instanceof 
NoOpCacheManager;
-        final boolean ehcacheEnabled = this.currentCacheManager instanceof 
JCacheCacheManager;
-
-        // final boolean distributedCacheEnabled = false;
+        final boolean noCacheEnabled = currentCacheManager == 
defaultCacheManager;
+        final boolean ehCacheEnabled = currentCacheManager == ehCacheManager;
 
         final EnumOptionData noCacheType = 
CacheEnumerations.cacheType(CacheType.NO_CACHE);
         final EnumOptionData singleNodeCacheType = 
CacheEnumerations.cacheType(CacheType.SINGLE_NODE);
-        // final EnumOptionData multiNodeCacheType =
-        // CacheEnumerations.cacheType(CacheType.MULTI_NODE);
 
         final CacheData noCache = CacheData.instance(noCacheType, 
noCacheEnabled);
-        final CacheData singleNodeCache = 
CacheData.instance(singleNodeCacheType, ehcacheEnabled);
-        // final CacheData distributedCache =
-        // CacheData.instance(multiNodeCacheType, distributedCacheEnabled);
+        final CacheData singleNodeCache = 
CacheData.instance(singleNodeCacheType, ehCacheEnabled);
 
-        final Collection<CacheData> caches = Arrays.asList(noCache, 
singleNodeCache);
-        return caches;
+        return Arrays.asList(noCache, singleNodeCache);
     }
 
     public Map<String, Object> switchToCache(final boolean ehcacheEnabled, 
final CacheType toCacheType) {

Review Comment:
   Probably I missed (a lot of) the conversation around this feature... but is 
there really a use case where you have to switch cache implementation during 
runtime? That seems to me such an important architectural decision that I would 
say it is done way before any instance of Fineract is running, at the least you 
would decide if EH Cache is enough or if you need it at all (I'd say the answer 
here is always yes... but not sure if you guys discussed a use case where no 
cache is desirable).
   BTW: multi-node cache... Redis is your friend... 1st class support in Spring 
Boot and works really great (read: performant).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to