Spring Boot可达缓存大小 [英] Spring Boot Cachable Cache Size

查看:152
本文介绍了Spring Boot可达缓存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配置我的缓存大小.我正在使用 @EnableCaching .这是我的缓存存储库.

I want to to configure my cache size. I am using @EnableCaching. Here is my cached repository.

供应商存储库

public interface VendorRepository extends Repository<Vendor, Long> {

@Cacheable("vendorByUsername")
Vendor getVendorByUsername(String username);

@CacheEvict(value = {"vendorByUsername", "vendor", "vendors"}, allEntries = true)
Vendor save(Vendor vendor);

@Cacheable("vendor")
Vendor findOne(Long id);

@Cacheable("vendors")
List<Vendor> findAll();
}

目前运行良好,但我想设置最大缓存大小.如何在我的主配置文件中进行配置?

It is working good right now but I want to set maximum cache size. How can I configure this in my main config file?

推荐答案

@ Jaiwo99 是正确的.

Spring的缓存抽象不处理特定的语义和低级"缓存.管理"的细节.缓存的内容(例如大小或类似相关的驱逐/到期).这在很大程度上是由于这些低层管理详细信息(从1个缓存提供程序到下一个缓存提供程序)差异很大.

Spring's Cache Abstraction does not deal with the particular semantics and "low-level" details of "managing" a cache's contents (such as as size, or similarly related, eviction/expiration). This is due in large part because these low-level management details vary greatly from 1 caching provider to the next.

例如,某些缓存提供程序/实现是高度分布式的,具有用于一致性,冗余性和控制延迟的机制等不同的策略.这样,如果某些提供者甚至没有实现所述特征,或者具有非常不同的一致性",则在这些特征之上提供一致的抽象将是非常困难的.政策等.

For instance, some caching providers/implementations are highly distributed, with different policies for consistency, redundancy and mechanisms that control latency, and so on. As such, it would be very difficult to provide a consistent abstraction on top of these features given some provider don't even implement said features, or have very different "consistency" policies, etc.

无论如何,《 Spring参考指南》中的这一部分可能总结得最好……

Anyway, this section in the Spring Reference Guide probably sums it up best...

8.7.如何设置TTL/TTI/驱逐策略/XXX功能?

8.7. How can I Set the TTL/TTI/Eviction policy/XXX feature?

直接通过您的缓存提供程序.缓存抽象是一种抽象,而不是缓存实现.您使用的解决方案可能支持其他解决方案不支持的各种数据策略和不同的拓扑(例如,JDK ConcurrentHashMap —暴露在缓存抽象中将是无用的,因为没有后备支持).应该通过后备缓存(配置时)或通过其本机API直接控制此类功能.

Directly through your cache provider. The cache abstraction is an abstraction, not a cache implementation. The solution you use might support various data policies and different topologies that other solutions do not support (for example, the JDK ConcurrentHashMap — exposing that in the cache abstraction would be useless because there would no backing support). Such functionality should be controlled directly through the backing cache (when configuring it) or through its native API.

https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache-specific-config

干杯!

这篇关于Spring Boot可达缓存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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