javaspringcachingcaffeine

How to create Caffeine cache that has no max value and does not expire?


I have implemented a Caffeine cache as follows:

private static Cache<String, MyObject> MyObjectCache = Caffeine.newBuilder()
    .build();

How can I ensure that the cache has no max size and does not expire?


Solution

  • A Caffeine cache can be implemented with no max value and no expiration by the following:

    private static Cache<String, MyObject> MyObjectCache = Caffeine.newBuilder()
        .build();
    

    I.e. it is created without a max value and expiration as default.