[英]What is the best way to store often used (not changeable) List, Map?
What is the best way to store often used (not changeable) List, Map? 存储常用(不可更改)列表,地图的最佳方法是什么?
Is it better to use @Cacheable
over creating list in the service layer on @PostConstruct
? 使用
@Cacheable
不是在@PostConstruct
的服务层中创建列表更好吗?
I would say @Cacheable
is better because you're not tied to a specific caching implementation. 我会说
@Cacheable
更好,因为您不依赖于特定的缓存实现。 Also it's less intrusive on the code. 另外,它对代码的干扰也较小。 As specified on Spring Reference Manual Section 29.3.1 , caching a method that finds a book by ISBN just looks like this:
正如Spring参考手册第29.3.1节中所指定的那样 ,缓存一种通过ISBN查找书籍的方法如下所示:
@Cacheable("books")
public Book findBook(ISBN isbn) {...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.