Skip to content

Conversation

@fx88
Copy link

@fx88 fx88 commented Mar 6, 2025

"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 added 2 commits February 17, 2025 13:32
…sCache-Beans, to avoid unnecessary RedisCache instantiations.

Feature: Add "Bypassing"-Cache by existing DynamicCacheManager pattern, if redis is disabled.
Feature: Add a dynamic Cache creation without having an explicit configuration by using DefaultCacheConfiguration.

Signed-off-by: Ferdinand Armbruster <ferdinand.armbruster@mercedes-benz.com>
…sCache-Beans, to avoid unnecessary RedisCache instantiations.

Feature: Add "Bypassing"-Cache by existing DynamicCacheManager pattern, if redis is disabled.
Feature: Add a dynamic Cache creation without having an explicit configuration by using DefaultCacheConfiguration.

Signed-off-by: Ferdinand Armbruster <ferdinand.armbruster@mercedes-benz.com>
@CLAassistant
Copy link

CLAassistant commented Mar 6, 2025

CLA assistant check
All committers have signed the CLA.

@graemerocher graemerocher requested a review from sdelamo March 6, 2025 17:03
@graemerocher graemerocher moved this to Ready for Review in 4.9.0 Release Mar 6, 2025
@fx88
Copy link
Author

fx88 commented Mar 27, 2025

@sdelamo / @graemerocher any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants