- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从我的微服务(SERVICE-A)中,我调用了另一个微服务(SERVICE-B)的 rest api 调用以登录并获取访问 token ,该 API 将使用该 token 的 TTL 进行响应。
我需要缓存 token ,直到 SERVICE-B 响应的 TTL(秒)。所以我的实现如下,
@Cacheable("USERTOKEN")
public String getUserToken()
{
//Hits Service-B
//Gets token and TTL as a response from Service-B
//Returns Token or Token with TTL
}
我需要将上述方法更改为
@Cacheable("USERTOKEN")
public String getUserToken()
{
//Hits Service-B
//Gets token and TTL as a response from Service-B
//Sets expiry time for "USERTOKEN" cache <-- this needs to be added
//Returns Token or Token with TTL
}
即使在从 getUserToken() 返回之后,如果可以使用 getUserToken() 返回的 TTL 为“USERTOKEN”缓存设置过期时间,它也会很好。我们可以为驱逐设置预定,但这将是一个静态时间段。但在这里我需要根据来自 Service-B 的响应将其设置为动态值。我怎样才能做到这一点。
最佳答案
如果您使用 caffeine cache ,您可以使用不同的过期策略:
来自 caffeine wiki page :
// Evict based on a varying expiration policy
LoadingCache<Key, Graph> graphs = Caffeine.newBuilder()
.expireAfter(new Expiry<Key, Graph>() {
public long expireAfterCreate(Key key, Graph graph, long currentTime) {
// Use wall clock time, rather than nanotime, if from an external resource
long seconds = graph.creationDate().plusHours(5)
.minus(System.currentTimeMillis(), MILLIS)
.toEpochSecond();
return TimeUnit.SECONDS.toNanos(seconds);
}
public long expireAfterUpdate(Key key, Graph graph,
long currentTime, long currentDuration) {
return currentDuration;
}
public long expireAfterRead(Key key, Graph graph,
long currentTime, long currentDuration) {
return currentDuration;
}
})
.build(key -> createExpensiveGraph(key));
关于java - Spring boot - 使用动态 TTL 周期驱逐缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64059670/
Cassandra 中的这种行为似乎违反直觉,我想知道为什么会发生这种情况,并可能解决这个问题。 假设我有一个包含三列的表: pk ,主键,一个 text类型, foo , bigint , 和 ba
我正在尝试在 java.security 文件中的网络地址缓存 TTL 设置 X 秒,但似乎更改不会影响缓存。我的请求仍然发送到旧机器。 我已将我的应用程序作为 WAR 托管在 Tomcat 中。 T
我正在使用 Amazon CloudFront,但在从 iOS 应用程序上传图像时遇到了一个奇怪的问题。所有图像都在服务器上排队并由工作人员处理,因此实际照片在上传后几秒钟才可用。 但是,该应用程序可
AWS CloudFront 默认缓存行为允许自定义最小 TTL、最大 TTL 和默认 TTL 值。我反复浏览了文档,但无法理解默认 TTL 和最大 TTL 之间的实际区别。例如,如果我在默认 TTL
我一直在关注有关设置 haproxy 和 varnish 的教程。 ( Link ) 但是,该教程是几年前编写的。我一直在尝试更改 V3 varnish 配置,并在这部分遇到了问题: sub vcl_
请告诉我,这些概念之间有什么区别?我在 Varnish 的文档中没有找到任何答案。他们只是操作这些概念,仅此而已。 什么更适合用于缓存: Cache-control header 中的 beresp.
我一直在阅读 Cloudfront 文档,我想确保我的计划是合理的。我有一个后端 API,结构为 EC2 HTTP 服务器,内容经常更新(每秒几次更改)。这是我的理解: 我不应该将此 HTTP 服务器
在 Java 中,有没有办法控制在套接字上发送的数据包的 IP header 的 TTL? 最佳答案 显然只在多播套接字上,它有: MulticastSocket.setTimeToLive(int
我有一个要求,当传递日期属性字段时,我们希望触发两件事: 将要删除的记录移动到另一个表。 调用一个函数来执行其他操作。 我理解 TTL 只是在日期字段被触发时删除记录。我可以将额外的逻辑挂接到它吗?
假设我在 second-1 处插入一列,在 second-2 处插入另一列。表的默认 TTL 设置为 10 秒,例如: 问题 1 : data1 和 data2 会在 10 秒后被删除还是 data
我很难理解 AeroSpike 文档中的以下内容: http://www.aerospike.com/docs/client/python/usage/kvs/record-structure.htm
我正在使用 RabbitMq 非常棒的消息代理,但我需要的是队列中有很长的消息备份时间。因此,如果消息未到达当时处于非事件状态的某些消费者,并且他们在几分钟后处于事件状态,则最终应通过扇出交换将消息传
到目前为止 i know ,目前 mongodb TTL 由 expireAfterSeconds 索引管理,它是为集合中的所有文档设置的。 那么是否有任何内置方法可以将过期设置为单个文档?,谢谢 最
我已经执行了这个命令来在 mongodb 上设置一个 TTL 索引, db.sessions.ensureIndex({'expiration':1},{"expireAfterSeconds": 3
使用 Java,我可以扫描 Cassandra 表并只更新一行的 TTL 吗?我不想更改任何数据。我只想扫描 Cassandra 表并设置几行的 TTL。 另外,使用java,我可以设置绝对的TTL吗
我知道 Cassandra 中的列有 TTL。但是也可以在一行上设置 TTL 吗?在每列上设置 TTL 并不能解决我的问题,如下面的用例所示: 在某些时候,一个进程想要删除一个带有 TTL 的完整行(
根据 HBase 规范: "ColumnFamilies can set a TTL length in seconds, and HBase will automatically delete ro
我有一件非常确定的事情要完成,并且在我自己编写整个事情之前,我想确保在 mongoose/mongoDB 中这是不可能的。 我检查了 mongoose-ttl 的 nodejs 和几个论坛,但没有找到
我有一个文档集合,它已经有一个名为 ttl 的属性,并且其值大于 0。现在我需要实现由 azure 。我怎样才能做到这一点? 最佳答案 除了运行某种类型的更新操作来更新所有 ttl 属性之外,不完全确
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-ttl-field.html似乎表明可以为每
我是一名优秀的程序员,十分优秀!