为 jpa 实体配置 ehcache.xml 还是使用注释?
当使用 ehcache 而不是定义像
<cache name="testonly.package.model.TestPOJOcategory"
maxElementsInMemory="200"
eternal="true"
overflowToDisk="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
/>
这样的语句时,可以直接定义独立于我们使用的任何缓存提供程序的内部实体吗?
@Cache(
type=CacheType.SOFT,
size=64000
expiry=36000000,
coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS
)
参考:http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching (仅针对 EclipseLink 显示,不适用于 ehcache)
when using ehcache rather than defining statement like
<cache name="testonly.package.model.TestPOJOcategory"
maxElementsInMemory="200"
eternal="true"
overflowToDisk="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
/>
can directly define inside entity independent of whatever cache provider we using?
@Cache(
type=CacheType.SOFT,
size=64000
expiry=36000000,
coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS
)
reference: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching (it only showed for EclipseLink, not ehcache)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,即使大多数 JPA 持久性提供程序(如 Hibernate、EclipseLink 等)提供对二级缓存的支持,JPA 1.0 也未指定对二级缓存的支持。因此,在使用 L2 缓存时,您实际上使用的是非标准的 JPA 扩展,并且不能从一个提供商移植到另一个提供商。 Hibernate 的
@Cache
注释与 EclipseLink 的@Cache
注释,与 OpenJPA 的
@DataCache
注释。所有这些都是不同的,它们是专有的。如果您正在使用 Hibernate(这是我对您之前问题的理解),您不应该查看 EclipseLink 专有的东西(或者仅针对您的文化,但如果可以的话,这个问题超出了文化范围)。其次,是什么让您认为 EclipseLink 的
@Cache
< /a>注解和EHCache有什么关系? AFAIK,EclipseLink 使用自己的 缓存实现,与 EHCache 无关。事实上,我感觉你有点迷失在这里。你也许应该放慢一点,一步一步做事:选择一个解决方案,坚持下去,确定你必须做的事情,一件一件地实施,然后让整个事情运转起来。专注于你的目标,暂时停止收集更多信息,花一些时间来消化你学到的新东西。
First, even if most JPA persistence providers (like Hibernate, EclipseLink,...) provide support for second level cache(s), JPA 1.0 did not specify support of a second level cache. So, when playing with L2 cache, you are actually using JPA extensions which are not standard and are not portable from one provider to another. Hibernate's
@Cache
annotation is not the same than EclipseLink's@Cache
annotation and is not comparable with OpenJPA's@DataCache
annotation. All these are different, they are proprietary. If you are using Hibernate (which is my understanding of your previous questions), you shouldn't look at EclipseLink proprietary things (or for your culture only but this question goes beyond culture if I may).Second, what makes you think that EclipseLink's
@Cache
annotation has anything to do with EHCache? AFAIK, EclipseLink uses its own cache implementation which is not related to EHCache.Actually, I have the feeling that you are a bit lost here. You should maybe slow down a bit and do things step after step: choose one solution, stick with it, identify what you have to do, implements things one by one, and get the whole thing working. Focus on your goal, stop gathering more information for now, take some time to digest the new things you've learned.
据我所知,在 Hibernate 中我们有这样的东西,
这个 annotation 还有两个属性,
region
和include
。要设置大小、有效期和所有这些事情,我什么都不知道。我相信你应该考虑 EhCache 的文档。As far as I know in Hibernate we have something like this,
This annotation has two more attributes,
region
andinclude
. To set the size, expiry and all those things, I am not aware of anything. You should consider the docs of EhCache, I believe.