Kengo's blog

Technical articles about original projects, JVM, Static Analysis and TypeScript.

On-memory cache in Guava libraries

2 years ago, I introduced a cache implementation with LinkedHashMap. But if you want to use on-memory cache for your product, I recommend you to try the cache package of Guava libraries.
以前の記事でLinkedHashMapによるキャッシュ実装を紹介したのですが、がっつり使う予定があるならGuava librariesに含まれるキャッシュ実装を使用するほうがいいでしょう。

This library provides basic feature like limiting size, weak reference and soft reference. Of course fluent interface is one of the good point, because it changes out code readable.
サイズ制限はもちろんWeakReferenceやSoftReferenceも使えますし、何よりBuilderが「流れるようなインタフェース」を採用しているためとても読みやすいです。オンメモリキャッシュが有効な状況があるならば、試してみても良いでしょう。