Search code examples
guava

What is the default Maximum Size for a Google Guava Cache?


Given a Guava cache created with the code below is there a maximum cache size if one is not set?

LoadingCache<String, String> loadingCache = CacheBuilder.newBuilder().build(new CacheLoader<String, String>() {
    @Override
    public String load(String key) throws Exception
    {
        return key.toUpperCase();
    }
});

In my case I really want a cache with no upper bound in size. I am using the cache to store permissions for logged in users and will evict items from the cache on user logout or session expiry.


Solution

  • The default cache is unbounded: as the javadoc for CacheBuilder explains

    These features are all optional

    and

    By default cache instances created by CacheBuilder will not perform any type of eviction.