java - native EclipseLink : enable second level cache for some entities

标签 java caching eclipselink

在我们的项目中,EclipseLink 的“旧” native (非 JPA)版本仍在使用。使用工作台应用程序(生成 XML 配置文件和一些 Java 代码)来配置映射。

我们在工作台工具中看到的内容:看起来对于所有实体,缓存都启用了共享隔离级别(默认)。

我们在应用程序中看到的内容:没有实体被缓存

我们想要的:仅为少数实体启用二级缓存

编辑

EclipseLink Workbench 中的配置:

enter image description here

生成的 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/

相关文章:

java - groovy 无法通过方法调用解析

java - 在 maven pom.xml 中使用带有 classpathPrefix 的子目录

java - 简化自定义类型上 Collections.sort 的实现

java - 如果我实现 UTF-16 文件处理程序,它能否准确处理所有其他编码

php - 在类似 reddit 的网站上进行缓存的最佳方法

NHibernate 缓存过期

mysql - 使用 JPA 2.1、EclipseLink、JSF 2.0 的日志表

ios - NSFilemanager 上传新文件,但 UIWebView 显示缓存版本

java - 如果 JPA 查询花费太长时间,则关闭数据库 session

java - 从 DATE 到 java.time.LocalDate 的 JPA 转换器不适用于 Glassfish 4.1