quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.49k stars 2.59k forks source link

Config property to select Quarkus Cache backend #33248

Open AndreasPetersen opened 1 year ago

AndreasPetersen commented 1 year ago

Description

With the introduction of Redis as a backend for Quarkus Cache, it would be great with a config property to choose the backend used, just like we can easily configure which database to use.

For our testing and production environments, we want to run Redis, but for most local development and @QuarkusTest, we want to use the Caffiene backend, as this makes setup much easier.

I realize that Quarkus has a dev service for Redis, but my company uses computers that can't easily run Docker on them, so this is not really an option for us...

Implementation ideas

A new config property to select the backend for Quarkus Cache, for examle:

quarkus.cache.backend=redis
%test.quarkus.cache.backend=caffiene
quarkus-bot[bot] commented 1 year ago

/cc @gwenneg (cache)

mkouba commented 1 year ago

For our testing and production environments, we want to run Redis, but for most local development and @QuarkusTest, we want to use the Caffiene backend, as this makes setup much easier.

There's already quarkus.cache.type that could be used to use caffeine (default) or redis (if quarkus-redis-cache is present).

However, the Redis Cache guide does not mention this property at all?

CC @cescoffier @geoand

geoand commented 1 year ago

The property is set automatically IIRC

mkouba commented 1 year ago

The property is set automatically IIRC

Do you happen to remember where? I did not see this pattern in other extensions. And even if we somehow set it by default if the quarkus-redis-cache extension is present, we should probably also mention this in the docs.

geoand commented 1 year ago

https://github.com/quarkusio/quarkus/blob/8fd0657258aa5eaa231098f6508158c51b3d52b6/extensions/redis-cache/deployment/src/main/resources/application.properties

geoand commented 1 year ago

It was originally:

    @BuildStep
    RunTimeConfigurationDefaultBuildItem redisCacheByDefault() {
        return new RunTimeConfigurationDefaultBuildItem("quarkus.cache.type", "redis");
    }

but was changed to use the properties file

mkouba commented 1 year ago

https://github.com/quarkusio/quarkus/blob/8fd0657258aa5eaa231098f6508158c51b3d52b6/extensions/redis-cache/deployment/src/main/resources/application.properties

Uf, I didn't know this is even possible and TBH I don't find it very transparent for users (provided it's not documented)...

mkouba commented 1 year ago

BTW https://quarkus.io/guides/cache#configuring-the-underlying-caching-provider does not metion quarkus.cache.type either. It does mention quarkus.cache.enabled though.

geoand commented 1 year ago

We should definitely document it

holomekc commented 1 year ago

Hi. It would also be awesome to configure it per cache-name. The situation we face is that we use a redis cache, but also would like to use the caffeine cache in parallel. We use the redis cache for caching some partner system responses, but in the caffeine cache we want to cache the OIDC token from a pod injected via a kubernetes BoundedServiceAccountVolume. It does not really make much sense to cache it in redis.

Edit: Additional information. We also have a use-case where we cache data, which we cannot serialize. We need to use a custom caching solution now, because Jackson otherwise fails during serialization. In this situation it would also be helpful to select the caching backend per cache-name.