Using Guava cache with specifying expiration time

660 views
Skip to first unread message

Anurag Sinha

unread,
Sep 24, 2022, 4:34:07 AM9/24/22
to guava-discuss
Hi Team,
We are using the Cache Builder to build the instance of cache and we do not want to pass any expiration time period and wanted to handle the clean up later in the code programmatically . Code snippet as shown below:
CacheBuilder.newBuilder()
                .build(new CacheLoader<K, V>() {
                    @Override
                    public V load(K key) {
                        return loadingFunction.load(key);
                    }
                });
We wanted to understand that what would be the default time period of expiration if we don't set it explicitly. Will it be for all the time till we programmatically cleanUp the entries or any fixed default number?
 
Regards,
Anurag Sinha

Louis Wasserman

unread,
Sep 24, 2022, 12:08:17 PM9/24/22
to Anurag Sinha, guava-discuss
If no expiration period is specified, then entries will never expire.  Even calling cleanUp will not remove any entries, since cleanUp only removes entries whose time has expired.  (You can, of course, clear or manually remove entries in the map, but that is different from calling cleanUp.)

Louis Wasserman
wasserm...@gmail.com


--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/91bb3b44-3164-4594-8d5f-a0f231682b47n%40googlegroups.com.

Anurag Sinha

unread,
Sep 25, 2022, 9:59:44 AM9/25/22
to guava-discuss
Hi Louis,

Thanks for your quick response.
for removing the keys once we are done using a particular entry. 

Regards,
Anurag Sinha

Reply all
Reply to author
Forward
0 new messages