Java 如何在EclipseLink中清除/刷新缓存

Java 如何在EclipseLink中清除/刷新缓存,java,eclipselink,Java,Eclipselink,我在persistence.xml(我使用Eclipselink 2.6.4)中使用web应用程序中的以下设置: <properties> <property name="eclipselink.jdbc.cache-statements" value="true" /> <property name="eclipselink.cache.query-results" value="true" /> <prop

我在persistence.xml(我使用Eclipselink 2.6.4)中使用web应用程序中的以下设置:

<properties> 
    <property name="eclipselink.jdbc.cache-statements" value="true" />        
    <property name="eclipselink.cache.query-results" value="true" /> 
    <property name="eclipselink.ddl-generation.index-foreign-keys" value="true" />
    <property name="eclipselink.logging.level" value="OFF" />        
    <property name="eclipselink.persistence-context.close-on-commit" value="true" />        
    <property name="eclipselink.persistence-context.flush-mode" value="commit" />        
    <property name="eclipselink.persistence-context.persist-on-commit" value="false" />
</properties>

我正在使用
@Cacheable(false)
注释来防止缓存某些实体
@Cache
注释在2.6.4版中不再有效
我的问题是,是否有可能全局清除缓存?比如说每3小时一次

谢谢

默认情况下,一级缓存已启用,您无法禁用它。i、 e.persistence.xml文件中的任何设置都不会禁用一级缓存

只能通过调用

entityManager.clear()
query.setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH);
这将使后续查询(第一次)转到数据库,然后对象再次存储在缓存中

在本例中,您需要将entitymanager对象存储在某个寄存器中,并每隔3小时循环一次以调用clear()函数

您可以通过调用

entityManager.clear()
query.setHint("javax.persistence.cache.storeMode", CacheStoreMode.REFRESH);

为什么缓存注释不起作用?有关使缓存无效的信息,请参阅,注释不起作用的原因与我的IDE(netbeans)有关。导入包
javax.persistence.Cache
时出现了一个不兼容的类型错误。我必须导入正确的包(org.eclipse.persistence.annotations)。无论如何,缓存注释不是我正在寻找的解决方案。我需要一个全球性的。有吗?谢谢你所说的全局失效是什么意思?它只适用于EMF级别的共享缓存。如果有多个应用程序在运行,则可以研究缓存协调,这将允许每个应用程序侦听事件。看,我明白了,所以我必须更改每个实体,或者最好让它们都扩展一个超类,在这个超类中我定义了将被继承的缓存策略。这份文件很有趣。我需要一些时间投入进去。谢谢你,克里斯。