问题标签 [caffeine-cache]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - Play Framework 中的咖啡因缓存不返回缓存的响应
我在我的 java Play Framework 作业中使用 Caffeine 缓存实现来缓存传出的 http 请求,我看到尽管缓存已启动并正在运行,但我的服务仍然每次都访问外部服务器而不是返回值从缓存中。而且我看到日志中记录的密钥始终相同。
所以我看到freshnessLifetime
没有设置,所以这可能意味着缓存立即过期。但我仍然不知道如何在配置中设置它
我没有更改我的 java 代码,如果我需要这样做,我找不到任何示例,或者我只应该有一个缓存配置来处理所有传出请求。
我将不胜感激
我的build.sbt
包含:
我的reference.conf
包含:
我的application.conf
包含:
我在日志中看到:
[调试] - restclient.BaseRestClient - 使用 url http://localhost:9001/entities/v2/867386732 [trace] - palwacCachingAsyncHttpClient - 执行:request = Request(GET http://localhost:9001/entities/v2/ 867386732),handler = AsyncHandler(play.libs.ws.ahc.StandaloneAhcWSClient$ResponseAsyncCompletionHandler@65b0b233),future = null [debug] - palibs.ws.ahc.cache.AhcHttpCache - get: key = GET http://localhost: 9001/entities/v2/867386732 [调试] - palwacCachingAsyncHttpClient - 执行 GET http://localhost:9001/entities/v2/867386732: 结果 = List(ResponseEntry(CacheableResponse(status = CacheableHttpResponseStatus(code = 200, text = OK), headers = DefaultHttpHeaders [Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block, X-Content-类型选项:nosniff,X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:08 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1),GET ,Map(),Some(2020-10-02T10:44:08.760450-07:00[America/Los_Angeles]))) [trace] - ctcResponseSelectionCalculator - findMatchingResponse: request = CacheRequest(http://localhost:9001/entities/ v2/867386732,GET,TreeMap()),responses = List(StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap(Date -> List(Thu, 01 Oct 2020 17:44:08) GMT), Content-Type -> List(application/json), Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin, strict-origin-when-cross-origin) , X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-Cross-Domain -政策->List(master-only)),GET,Map())) [debug] - palwacCachingAsyncHttpClient - 执行 GET http://localhost:9001/entities/v2/867386732:从缓存中选择:ResponseEntry(CacheableResponse(status = CacheableHttpResponseStatus(code = 200, text = OK), headers = DefaultHttpHeaders[Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block, X-Content-Type-Options: nosniff, X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:08 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1),GET,Map(),Some(2020-10-02T10:44:08.760450-07:00[America/Los_Angeles])) [trace] - ctcCurrentAgeCalculator - calculateCurrentAge(headers :TreeMap(日期 -> 列表(星期四,2020 年 10 月 1 日 17:44:08 GMT),内容类型 -> 列表(应用程序/json),Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X- XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-Cross-Domain-Policies -> List(master-only)),现在:2020 -10-01T17:44:38.690992Z[GMT], requestTime: 2020-10-01T17:44:38.690274Z[GMT], responseTime: 2020-10-01T17:44:38.690981Z[GMT]) [trace] - ctcCurrentAgeCalculator2020-10-01T17:44:38.690981Z[GMT]) [trace] - ctcCurrentAgeCalculator2020-10-01T17:44:38.690981Z[GMT]) [trace] - ctcCurrentAgeCalculator
- calculateCurrentAge: currentAge = PT30S [debug] - ctcResponseServingCalculator - serveResponse: 为 'GET http://localhost:9001/entities/v2/867386732' 找到响应,年龄 = 30 [trace] - ctcResponseServingCalculator - noCacheFound: request = CacheRequest(http: //localhost:9001/entities/v2/867386732,GET,TreeMap()), response = StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap(Date -> List(Thu, 01 Oct 2020 17:44:08 GMT),Content-Type -> List(application/json),Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin,strict-origin- when-cross-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X -Permitted-Cross-Domain-Policies -> List(master-only)),GET,Map()) [trace] - ctcResponseServingCalculator - isCachedResponseFresh: request = CacheRequest(http://localhost:9001/entities/v2/867386732,GET,TreeMap()), response = StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap (日期 -> 列表(星期四,2020 年 10 月 1 日 17:44:08 GMT),内容类型 -> 列表(应用程序/json),内容长度 -> 列表(2144),推荐人策略 -> 列表(来源- when-cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type -Options -> List(nosniff), X-Permitted-Cross-Domain-Policies -> List(master-only)),GET,Map()) [trace] - ctcFreshnessCalculator - calculateFreshnessLifetime: [debug] - ctcFreshnessCalculator - calculateFreshnessLifetime: freshnessLifetime = None [调试] - ctcFreshnessCalculator - calculateFreshnessLifetime:结果 = PT0S [debug] - ctcResponseServingCalculator - isCachedResponseFresh:freshnessLifetime = PT0S,currentAge = PT30S [debug] - ctcResponseServingCalculator - isCachedResponseFresh:freshnessLifetime = PT0S,currentAge = PT30S [trace] - ctcResponseServingCalculator - isStaleResponseProhibited:request = CacheRequest(http://localhost :9001/entities/v2/867386732,GET,TreeMap()), response = StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap(Date -> List(Thu, 01 Oct 2020 17:格林威治标准时间 44:08),内容类型 -> 列表(应用程序/json),内容长度 -> 列表(2144),推荐人策略 -> 列表(起源时交叉起源,严格起源时交叉-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-跨域策略 ->List(master-only)),GET,Map()) [trace] - ctcResponseServingCalculator - isStaleResponseAllowed: PT30S, request = CacheRequest(http://localhost:9001/entities/v2/867386732,GET,TreeMap()), response = StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap(日期 -> 列表(周四,2020 年 10 月 1 日 17:44:08 GMT),内容类型 -> 列表(应用程序/json) , Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X -XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-Cross-Domain-Policies -> List(master-only)),GET, Map()) [debug] - ctcResponseServingCalculator - isStaleResponseAllowed:不允许过时的响应 [trace] - ctcResponseServingCalculator - canServeStaleAndRevalidate:response = StoredResponse(http://localhost:9001/entities/v2/867386732,200,TreeMap(Date -> List(Thu, 01 Oct 2020 17:44:08 GMT), Content-Type -> List(application/json ), Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-Cross-Domain-Policies -> List(master-only)),GET ,Map()) [trace] - ctcFreshnessCalculator - calculateFreshnessLifetime: [debug] - ctcFreshnessCalculator - calculateFreshnessLifetime: freshnessLifetime = None [debug] - ctcFreshnessCalculator - calculateFreshnessLifetime: result = PT0S [trace] - ctcFreshnessCalculator - calculateFreshnessLifetime: [debug] - ctcFreshnessCalculator - calculateFresh :freshnessLifetime = None [debug] - ctcFreshnessCalculator - calculateFreshnessLifetime: result = PT0S [debug] - palwacCachingAsyncHttpClient - serveResponse GET http://localhost:9001/entities/v2/867386732:响应过时,并且不允许过时的响应 - 重新验证staleIfError = false [trace] - palwacCachingAsyncHttpClient - buildValidationRequest: Request(GET http://localhost:9001/entities/v2/867386732), response = CacheableResponse(status = CacheableHttpResponseStatus(code = 200, text = OK), headers = DefaultHttpHeaders [ Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block, X-Content-Type-Options: nosniff,X-Permitted-Cross-Domain-Policies:master-only,日期:星期四,2020 年 10 月 1 日 17:44:08 GMT,内容类型:application/json,内容长度:2144],bodyParts 大小 = 1) [debug] - psaoanrNettyRequestSender - 使用池化通道 '[id: 0x1fac35f7, L:/127.0.0.1:49899 - R:localhost/127.0.0.1:9001]' 用于 'GET' 到 'http ://localhost:9001/entities/v2/867386732' [debug] - psaoanrNettyRequestSender - 使用开放通道 [id: 0x1fac35f7, L:/127.0.0.1:49899 - R:localhost/127.0.0.1:9001] 获取 '/ entity/v2/867386732' [trace] - psainhlogging.LoggingHandler/entities/v2/867386732' [trace] - psainhlogging.LoggingHandler/entities/v2/867386732' [trace] - psainhlogging.LoggingHandler
- [id: 0x1fac35f7, L:/127.0.0.1:49899 - R:localhost/127.0.0.1:9001] 写:107B
[调试] - psoanetty.handler.HttpHandler -
请求 DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE) GET /entities/v2/867386732 HTTP/1.1 host: localhost:9001 accept: / user-agent: AHC/2.1
响应 DefaultHttpResponse(decodeResult: success, version: HTTP/1.1) HTTP/1.1 200 OK Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin X-Frame-Options: DENY X-XSS-防护:1;mode=block X-Content-Type-Options: nosniff X-Permitted-Cross-Domain-Policies: master-only Date: Thu, 01 Oct 2020 17:44:38 GMT Content-Type: application/json Content-Length: 2144
[调试] - psaoanchannel.ChannelManager - 为通道添加密钥:http://localhost:9001 [id: 0x1fac35f7, L:/127.0.0.1:49899
- 严格起源时跨起源,X-Frame-Options:拒绝,X-XSS-Protection:1;mode=block, X-Content-Type-Options: nosniff, X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:38 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1) [trace] - ctcResponseCachingCalculator - isCacheable: request: CacheRequest(http://localhost:9001/entities/v2/867386732,GET,TreeMap()), response = OriginResponse(http ://localhost:9001/entities/v2/867386732,200,TreeMap(Date -> List(Thu, 01 Oct 2020 17:44:38 GMT), Content-Type -> List(application/json), Content-Length -> List(2144), Referrer-Policy -> List(origin-when-cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-XSS-防护:1;mode=block, X-Content-Type-Options: nosniff, X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:38 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1) [trace] - ctcSecondaryKeyCalculator - 计算:request = CacheRequest(http://localhost:9001/entities/v2/867386732,GET,TreeMap()), responseHeaders = TreeMap(Date -> 列表(周四,2020 年 10 月 1 日 17:44:38 GMT),内容类型 -> 列表(应用程序/json),内容长度 -> 列表(2144),推荐人策略 -> 列表(来源时间- cross-origin, strict-origin-when-cross-origin), X-Frame-Options -> List(DENY), X-XSS-Protection -> List(1; mode=block), X-Content-Type-Options -> List(nosniff), X-Permitted-Cross-Domain-Policies -> List(master-only)) [debug] - palibs.ws.ahc.cache.AhcHttpCache - put: key = GET http://localhost: headers = DefaultHttpHeaders[Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block, X-Content-Type-Options: nosniff, X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:38 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1),GET,Map(),Some(2020-10-02T10:44:38.771750-07:00[America/Los_Angeles])) [debug] - restclient.BaseRestClient - 响应状态 [200] for url [http://localhost:9001/entities/v2/867386732] [trace] - psainhlogging.LoggingHandler - [id: 0x1fac35f7, L:/127.0.0.1:49899 - R:localhost/127.0.0.1 :9001]读取完成[跟踪] headers = DefaultHttpHeaders[Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin, X-Frame-Options: DENY, X-XSS-Protection: 1; mode=block, X-Content-Type-Options: nosniff, X-Permitted-Cross-Domain-Policies: master-only, Date: Thu, 01 Oct 2020 17:44:38 GMT, Content-Type: application/json, Content-Length: 2144], bodyParts size = 1),GET,Map(),Some(2020-10-02T10:44:38.771750-07:00[America/Los_Angeles])) [debug] - restclient.BaseRestClient - 响应状态 [200] for url [http://localhost:9001/entities/v2/867386732] [trace] - psainhlogging.LoggingHandler - [id: 0x1fac35f7, L:/127.0.0.1:49899 - R:localhost/127.0.0.1 :9001]读取完成[跟踪]
- palwahc.cache.CacheableResponse - getResponseBody:
java - 咖啡因缓存 X509Certificate
我正在一个项目中开发一个选项,该选项使用 X509Certificate 加密一些数据。本项目使用 Spring Boot。我使用 BouncyCastle 库进行加密。
要加密数据,我必须从某个服务器下载收件人的证书。这很简单,我使用 Apache HttpClient。但是频繁的下载会给服务器带来很大的负担,所以我想缓存这个证书。
我有两种方法:
此方法从服务器下载证书
此方法检查证书是否已被吊销。
我的目标是缓存getFromServer方法。我需要设置缓存驱逐策略,即:
- 如果证书已过期,则驱逐证书。
- 如果证书已被吊销,则驱逐证书。
谁能帮我?
caching - 如何在 Micronaut 的应用程序 YAML 中定义 Duration 对象
我正在尝试在 micronaut 中定义一个 caffiene 缓存并通过应用程序 yaml 设置过期时间。
该文件表明
micronaut.caches.discovery-client.expire-after-write
应该定义为一个Duration
对象,但不清楚如何在 YAML 中这样做。
给出以下错误:
大概是因为该值被视为Integer
非Duration
java - 如何解决“Spring Cloud LoadBalancer 当前正在使用默认缓存。您可以切换到使用 Caffeine 缓存”警告?
如何解决Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it to the classpath.
spring boot中的警告?
java - 如何使用 Spring 配置 Caffeine 缓存
我有一个简单的 Spring 应用程序。我需要在一些每次调用都很昂贵的服务上实现缓存。
我有一个这样的配置类:
我的pom.xml
包括:
我有一种需要像这样缓存的方法:
每次我运行应用程序时,我都会得到java.lang.NoClassDefFoundError: com/github/benmanes/caffeine/cache/Caffeine
.
这是完整的堆栈跟踪:https ://textuploader.com/1eil3 我不确定我在哪里做错了,或者我是否遗漏了什么。
java - 没有 SpringBoot 的 Spring 缓存 Caffeine 集成
我想在我的 Spring 5 应用程序中集成 Caffeine Cache。我知道我需要 CaffeineCacheManager,但我没有课程。我发现的唯一方法是将 SpringBoot Starter Cache 包添加到 pom,但我不想使用 Spring Boot。
我的 pom 中有这个 Spring 包:
有什么办法可以在 Spring Boot 中使用 CaffeineCacheManager 类?谢谢。
实际上我正在使用此代码来配置缓存:
java - 使用缓存组件以在 Apache Camel 中将变量保存为全局变量
目标是使从主体中获取的变量可重用,以便将其也用于路径中的其他转换。更具体地说,目的是从接口获取令牌并将其用于进一步的访问,如图像中所示。流程图
要求是:
- 将变量保存一段可设置的时间。
- 管理变量以便在需要时获取它。
java-8 - 如何在 google Cache CacheLoader 中传递多个参数?
我想使用google Cache来缓存我的数据,所以我这样写代码。我发现它只能传递一个名为key的参数,但是在我的方法中,我有另一个参数,如何修复我的代码?
在我的 queryData 方法中,我有三个参数,如何更改我的代码?
spring-boot - 动态设置缓存 expireAfterWrite 属性 - Caffeine 和 Spring WebFlux
我正在使用咖啡因缓存来存储使用 webClient WebFlux 获得的授权令牌。我已将 expireAfterWrite 设置为 application.yml 文件中的硬编码值,如下所示:
令牌是使用带有 Spring WebFlux 的 WebClient 获得的,如下代码所示:
我在 .doOnNext() 方法中成功发出/返回数据后存储令牌,但我需要能够根据 expiresIn 属性设置过期时间或刷新缓存的硬编码过期时间,该属性是响应对象,
任何想法将不胜感激。