独立 java 应用程序的缓存/映射策略

Caching / Mapping strategy for standalone java application

我有一个 SQL Table,磁盘大小约为 50 GB。 table 是只读的,因此非常适合缓存。为了更快和更频繁地查找,什么是理想的 -

  1. Java 8 哈希映射。
  2. 内存缓存。
  3. 休眠 EH 缓存。 或者更好的东西?

(假设有 200 GB 的主内存可用于 JVM)。

您可以开始尝试 Guava cache(Google Java 1.6+ 的核心库)

Generally, the Guava caching utilities are applicable whenever:

  • You are willing to spend some memory to improve speed.
  • You expect that keys will sometimes get queried more than once.
  • Your cache will not need to store more data than what would fit in RAM. (Guava caches are local to a single run of your application.
    They do not store data in files, or on outside servers.

    If this does not fit your needs, consider a tool like Memcached.)

免责声明:我在 Ehcache 上为 Terracotta 工作

另一种选择是使用即将推出的 Ehcache 3 及其堆外层。这将允许您将整个 table 缓存在 RAM 中,但不受 GC 的控制,因此不会成为暂停时间的来源。