DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Caffeine cache

原文链接

  1. 愿意消耗一些内存空间来提升速度
  2. 预料到某些键会被多次查询
  3. 缓存中存放的数据总量不会超出内存容量

Caffeine提供三类驱逐策略:

  1. 基于大小(size-based)
  2. 基于时间(time-based)
  3. 基于引用(reference-based)

原文链接1

who is the author of ConcurrentLinkedHashMap on which Guava cache is based.

guava out

  • guava sync operation
  • non-blocking without aware

Caffeine uses both a Least Recently Used (LRU) eviction policy and a frequency-based admission policy relying on CountMin sketch. It has a better hit rate than LRU for many workloads.

使用ring buffers的方式,The ring buffer approach avoids allocation, is bounded (lossy), and cheaper to operate against.

Caffeine uses ring buffers to record & replay events, whereas Guava uses ConcurrentLinkedQueue.