Skip to content

Fix "BeanInstantiationException" + Add Dynamic cacheEntry creation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 6.7.x
Choose a base branch
from

Conversation

fx88
Copy link
Collaborator

@fx88 fx88 commented Feb 27, 2025

"THIS PR IS ONLY FOR INTERNAL MB REVIEW"

"BeanInstantiationException" on redis.enabled=false

In some cases it 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 an 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 instantiated, when Redis is enabled.
Additionally BypassDynamicCacheManageris added, to bypass the the cache mechanism, by using the DynamicCacheManger functionality of the Micronaut-Cache implementation.

Dynamic Cache 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 <[email protected]>
…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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant