2016-06-12 66 views
0

我想配置我的缓存大小。我正在使用@EnableCaching。这是我的缓存存储库。Spring Boot Cachable Cache Size

VendorRepository

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(); 
} 

它是现在工作不错,但我想设置最大缓存大小。我如何在我的主配置文件中配置这个?

+0

它取决于您使用哪种缓存实现。春天cahe只是一个抽象层 – Jaiwo99

+0

我不使用任何任何实现。我将使用Ehcache。谢谢。 – fatiherdem

回答

1

@ Jaiwo99是正确的。

Spring的缓存抽象不处理缓存内容(如大小或类似相关的驱逐/到期)的特定语义和“低级”细节。这主要是因为这些低级管理细节在1缓存提供者和下一个缓存提供者之间差别很大。例如,一些缓存提供者/实现是高度分布的,具有不同的一致性策略,冗余度和控制延迟的机制等等。因此,在这些功能之上提供一致的抽象是非常困难的,因为某些提供商甚至不实现所述功能,或者具有非常不同的“一致性”策略等等。

无论如何,本节在Spring参考指南大概总结说最好...

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-specific-config

干杯!

+0

谢谢澄清,我会使用EhCache,这很容易使用,因为我看到。 – fatiherdem