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

1

6

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?

Contrapuntist answered 18/12, 2019 at 16:47 Comment(3)
You've just done it in that code sample, haven't you? You've provided no maximum size and no expiry time after read or write, so I can't see why it would enforce a maximum size or expire.Industrialize
@MichaelBerry is correct. Unlike some other caching libraries, Caffeine does not have implicit default bounds. The obvious code, yours, works exactly how you would expect it to.Kaleidoscopic
OK I was not aware the defaults did not have bonds. feel free to answer so I can acceptContrapuntist
C
5

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.

Contrapuntist answered 24/1, 2020 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.