micronaut-redis icon indicating copy to clipboard operation
micronaut-redis copied to clipboard

Fix "BeanInstantiationException" + Add Dynamic cacheEntry creation

Open fx88 opened this issue 8 months ago • 2 comments
trafficstars

"BeanInstantiationException" on redis.enabled=false

In some cases it necessary to deactivate the caching mechanism, for example in a local development setting. Therefore I want to disable Redis and bypass the caching mechanism. Currently there is a flag to disable Redis redis.enable=false, but this leads to a BeanInstantiationException on the first load of the CacheManager.

Caught unexpected error 'BeanInstantiationException' on API level with message: Error instantiating bean of type [io.micronaut.cache.DefaultCacheManager]

Example configuration.

application.yaml

redis:
  enabled: false
  host: localhost
  port: 6379

  caches:
    test-cache:
       expire-after-write: 24h

This PR should fix this Error by considering the "redis.enable"-property in the RedisCache-Class. It should only be instantiated, when Redis is enabled. Additionally BypassDynamicCacheManageris added, to bypass the cache mechanism, by using the DynamicCacheManger functionality of the Micronaut-Cache implementation.

Dynamic CacheEntry creation without having an explicit configuration by using DefaultCacheConfiguration.

application.yaml

redis:
  enabled: false
  host: localhost
  port: 6379
  dynamic:
    enabled: true

As an additional feature a DynamicCacheManger is added. It will use the DefaultCacheConfiguration to create dynamically CacheEntries without having an explicit configuration in the application.yaml.

This should decouple more the Configuration with the Annotations in the code. It also should behaves like the Hazelcast Cache implementation, that also creates dynamic CacheEntries if a configuration is missing.

fx88 avatar Mar 06 '25 10:03 fx88

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 06 '25 10:03 CLAassistant

@sdelamo / @graemerocher any news?

fx88 avatar Mar 27 '25 19:03 fx88