![](/img/trans.png)
[英]Circuit-break L2 cache in Hibernate in case of redis connection issues
[英]How to use Redis as L2 cache on Hibernate?
我有一個 Spring Boot 應用程序,需要在休眠時將 Redis 設置為 l2 緩存。
我的道具文件看起來像:
spring.jpa.properties.hibernate.cache.region.factory_class = package.CustomRegionFactory
spring.jpa.properties.hibernate.cache.redisson.fallback=false
我創建了一個自定義區域工廠,因為我不想使用 json 或 yaml 文件。 (現在,參數是硬編碼的)。 CustomRegionFactory 類看起來像:
public class CustomRegionFactory extends RedissonRegionFactory {
@Override
public RedissonClient createRedissonClient(Properties properties) {
Config config = new Config();
config.useSingleServer().setAddress("redis://127.0.0.1:6379").setRetryInterval(1500)
.setRetryAttempts(3).setConnectTimeout(10000)
.setClientName("client1");
return Redisson.create(config);
}
}
使用 redis-cli 我發現使用命令keys *
時列出了所有用@Cacheable
注釋的實體。 到這里為止,我認為一切正常,但是使用 postgres 日志記錄資源我發現查詢正在訪問數據庫。
有人有任何提示可以使其正常工作嗎?
我發現在 hibernate 中使用 @Cacheable 可以解決所有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.