简体   繁体   English

如何将ehcache自填充缓存实现为休眠二级缓存

[英]How to implement ehcache self populating cache as hibernate second level cache

I am just exploring on Ehcache self populating cache as hibernate second level cache . 我只是在探索Ehcache自填充缓存作为休眠的二级缓存

Is hibernate support self populating cache? 休眠是否支持自填充缓存?
Can anybody help me find few sample implementations/docs related to this topic? 有人可以帮我找到一些与此主题相关的示例实现/文档吗?

VamsiKrishna, I'm not really sure what you try to achieve here, but I guess you want to avoid that two threads load the same entity from the DB. VamsiKrishna,我不太确定您想在这里实现什么,但是我想您想避免两个线程从数据库加载相同的实体。 Now, I'm afraid you won't be able to achieve this. 现在,恐怕您将无法实现这一目标。 First, Hibernate doesn't store entities in the cache, but dehydrated representation of these. 首先,Hibernate不在高速缓存中存储实体,而是对它们进行脱水表示。 Creating these and then putting them so that the Ehcache layer can deal with them (they might rewrapped in some other internal types iirc), is all I believe not possible (Type accessibility would be one issue). 创建这些文件,然后放置它们,以便Ehcache层可以处理它们(它们可能会重新包装在其他内部类型iirc中),我认为这是不可能的(类型可访问性将是一个问题)。

Also, you could use BlockingCache to mimic the behaviour and let Hibernate populate the Cache. 另外,您可以使用BlockingCache模仿行为,然后让Hibernate填充Cache。 The issue with that is that Hibernate won't put null values in the cache if I remember correctly. 这样做的问题是,如果我没记错的话,Hibernate不会在缓存中放入空值。 Not doing so would eventually lock your entire Cache. 否则,最终将锁定整个缓存。

Long story short, I think you're better off letting Hibernate deal with the concurrent access to the Cache (controlled by the cache access strategy) by itself, as nothing in there is really meant for a user to do... 长话短说,我认为您最好让Hibernate自己处理对Cache的并发访问(由缓存访问策略控制),因为其中的任何内容实际上都不意味着用户要做...

From ehcache website - http://www.ehcache.org/documentation/user-guide/hibernate#Configure-Ehcache-as-the-Second-Level-Cache-Provider 从ehcache的网站- http://www.ehcache.org/documentation/user-guide/hibernate#Configure-Ehcache-as-the-Second-Level-Cache-Provider

In hibernate.cfg.xml add 在hibernate.cfg.xml中添加

<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM