[英]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.