2

我正在尝试在 micronaut 中定义一个 caffiene 缓存并通过应用程序 yaml 设置过期时间。

文件表明

micronaut.caches.discovery-client.expire-after-write应该定义为一个Duration对象,但不清楚如何在 YAML 中这样做。

---
micronaut:
  application:
    name: example-service
  caches:
    example-cache:
      expire-after-write: 86400

给出以下错误:

Internal Server Error: Failed to inject value for parameter [expireAfterWrite] of method [setExpireAfterWrite] of class: io.micronaut.cache.caffeine.DefaultCacheConfiguration

Message: Error resolving property value [micronaut.caches.example-cache.expire-after-write]. Property doesn't exist
Path Taken: new $ExampleControllerDefinition$Intercepted(BeanContext beanContext,Qualifier qualifier,[Interceptor[] interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new DefaultSyncCache([CacheConfiguration cacheConfiguration],ApplicationContext applicationContext,ConversionService conversionService) --> DefaultCacheConfiguration.setExpireAfterWrite([Duration expireAfterWrite])
io.micronaut.http.client.exceptions.HttpClientResponseException: Internal Server Error: Failed to inject value for parameter [expireAfterWrite] of method [setExpireAfterWrite] of class: io.micronaut.cache.caffeine.DefaultCacheConfiguration

大概是因为该值被视为IntegerDuration

4

1 回答 1

4

看来您可以像这样简单地做到这一点:

---
micronaut:
  application:
    name: example-service
  caches:
    example-cache:
      expire-after-write: 24h
于 2020-11-24T15:30:15.150 回答