[英]using ehcache in a dropwizard project
我正在使用 dropwizard 创建一个 RESTful 服务。 为了避免重击数据库,我正在寻找一个很好的 java 缓存解决方案。 在网上搜索使我找到了 ehcache。 我已经阅读了一些文档,但目前我不清楚如何在 dropwizard 项目中使用 ehcache。
例如,配置文件去哪里了? 我只需要一些东西来帮助我开始使用缓存。
如果这很难集成,那么最适合 dropwizard 项目的缓存解决方案是什么?
谢谢!
如果您最终想要一个更简单(比 ehcache)的缓存框架/API,请考虑使用来自 guava 的 CacheBuidler:
https://code.google.com/p/guava-libraries/wiki/CachesExplained
典型的缓存实现和使用只需要几行代码,不需要配置文件。
我知道这是一个老问题,但我已经能够设置它。 就是这样。
hibernate
版本。 您可以从dropwizard-hibernate
包的依赖项中dropwizard-hibernate
。 例如。 dropwizard-hibernate:1.3.12
取决于hibernate-core:5.2.18.Final
。compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.18.Final'
# For documentation on available options please refer io.dropwizard.db.DataSourceFactory
database:
# any properties specific to your JDBC driver:
properties:
# Enable second level cache with EhCache
hibernate.cache.use_second_level_cache: true
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
@org.hibernate.annotations.Cache
文档我发现这篇文章是一个好的开始。 https://www.baeldung.com/hibernate-second-level-cache 。 还有其他类型的缓存,如查询缓存等,这可能会有所帮助,具体取决于您的用例。
如果这有帮助,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.