Spring @Cacheable默认TTL [英] Spring @Cacheable default TTL

查看:201
本文介绍了Spring @Cacheable默认TTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常在Spring-boot应用程序中将 @Cacheable 与缓存配置结合使用,并为每个缓存设置特定的TTL(生存时间)。

I generally use the @Cacheable with a cache config in my spring-boot app and set specific TTL (time to live) for each cache.

我最近继承了一个使用 @Cacheable 的spring boot应用程序,没有明确说明缓存管理器和ttl。

I recently inherited a spring boot app that uses @Cacheable without explicitly stating a cache manager and ttl. I will be changing it to be explicit.

但是当没有明确的内容时,我无法找出默认值。

But I am not able to find out what are the defaults when there is nothing explicit.

我确实查看了文档,但是在那里什么也没找到

I did look at the docs but found nothing there

推荐答案

Spring 很清楚有关TTL / TTI(到期)和逐出策略的信息,如《 Spring框架参考指南》 此处。换句话说,默认值完全取决于通过 Spring缓存抽象 Spring Boot 应用程序一起使用的基础数据存储(aka缓存提供程序)。

Spring is pretty clear about TTL/TTI (Expiration) and Eviction policies as explained in the core Spring Framework Reference Guide here. In other words, the "defaults" depend entirely on the underlying data store (a.k.a. caching provider) used with the Spring Boot app via the Spring Cache Abstraction.

虽然 Arpit's 解决方案是一个不错的解决方法,并且是跨不同缓存提供程序(数据存储)的通用可转移解决方案,但它也无法涵盖更具体的到期/收回策略,例如在到期/收回时执行的操作类型,例如OVERFLOW_TO_DISK或LOCAL_DESTROY(例如,在高可用性(可能基于分区),分布式方案中)或INVALIDATE等。

While Arpit's solution is a nice workaround and a generic, transferable solution across different caching providers (data stores), it also cannot cover more specific expiration/eviction policies, such as the kind of action to perform when an expiration/eviction, say OVERFLOW_TO_DISK, or LOCAL_DESTROY only (such as in a Highly Available (maybe zoned based), distributed scenario), or INVALIDATE, etc.

通常,根据UC,逐出所有条目是不可接受的选择,并且是 Spring 将这种职责委托给缓存提供程序的原因之一,因为此功能有所不同

Usually, depending on the UC, evicting "all" entries is not an acceptable option and is one of the reasons why Spring delegates this responsibility to caching provider as this capability varies highly between 1 provider to another.

总之...肯定要查看您的UC要求并配对适当的缓存提供程序具有与您的UC相匹配的功能。 Spring 支持来自 rel = nofollow noreferrer> Redis Apache Geode / Pivotal GemFire Hazelcast 等,在这方面各有不同/相似的功能。

In summary... definitely review the requirements for your UC and pair the appropriate caching provider with the capabilities that match your UC. Spring supports a wide variety of caching providers from Redis to Apache Geode/Pivotal GemFire to Hazelcast, etc, each with different/similar capabilities in this regard.

这篇关于Spring @Cacheable默认TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆