MarcGiffing / bucket4j-spring-boot-starter

Spring Boot Starter for Bucket4j
Apache License 2.0
298 stars 63 forks source link

AsyncCacheResolver could not be found, with multiple caches caffeine #319

Open amirdikhanbayev opened 1 month ago

amirdikhanbayev commented 1 month ago
@Bean
    @Primary
    public SyncCacheResolver bucket4jCacheResolver() {
        final CachingProvider cachingProvider = Caching.getCachingProvider();
        CaffeineConfiguration<Object, Object> configuration = new CaffeineConfiguration<>();
        configuration.setExpireAfterWrite(OptionalLong.of(Duration.ofHours(1).toNanos()));
        configuration.setMaximumSize(OptionalLong.of(1000000));
        CacheManager cacheManager = cachingProvider.getCacheManager();
        cacheManager.createCache("rateLimiting", configuration);
        return new JCacheCacheResolver(cacheManager);
    }

Hello! After implementing this config still have ChacheResolver exception

Description:

Parameter 2 of constructor in com.giffing.bucket4j.spring.boot.starter.Bucket4jStartupCheckConfiguration required a bean of type 'com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver' that could not be found.

Action:

Consider defining a bean of type 'com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver' in your configuration.

amirdikhanbayev commented 1 month ago

UPD:

Okey like i saw JCacheCacheResolver doesn't implement AsyncCacheResolver

public class JCacheCacheResolver extends AbstractCacheResolverTemplate<String> implements SyncCacheResolver {
    private final CacheManager cacheManager;

    public JCacheCacheResolver(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }

    public String castStringToCacheKey(String key) {
        return key;
    }

    public boolean isAsync() {
        return false;
    }

Is it will support late? Or we have other way to config without AsyncCacheResolver?