在我们的项目中,EclipseLink 的“旧” native (非 JPA)版本仍在使用。使用工作台应用程序(生成 XML 配置文件和一些 Java 代码)来配置映射。
我们在工作台工具中看到的内容:看起来对于所有实体,缓存都启用了共享隔离级别(默认)。
我们在应用程序中看到的内容:没有实体被缓存
我们想要的:仅为少数实体启用二级缓存
编辑
EclipseLink Workbench 中的配置:
生成的 XML 配置:
[...]
<refresh-cache-policy/>
<caching-policy/>
[...]
生成的项目代码:
// ClassDescriptor Properties.
descriptor.useSoftCacheWeakIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteSoftCacheWeakIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
descriptor.setReadOnly();
descriptor.setAlias("SomeAlias");
// Cache Invalidation Policy
TimeToLiveCacheInvalidationPolicy policy = new TimeToLiveCacheInvalidationPolicy(1000);
policy.setShouldUpdateReadTimeOnUpdate(false);
descriptor.setCacheInvalidationPolicy(policy);
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
最佳答案
目前,我们的解决方法是使用 ehcache 和 Spring 来缓存方法调用。
一旦我们可以迁移到 JPA,我们很可能会使用 ehcache,所以我想这还不错。
关于java - native EclipseLink : enable second level cache for some entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45061350/