Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:20:14+00:00 2026-06-05T18:20:14+00:00

I am using the Google Guava CacheBuilder to create a Cache instance. My code

  • 0

I am using the Google Guava CacheBuilder to create a Cache instance. My code looks something like the following:

return CacheBuilder.newBuilder()
            .initialCapacity(initialCapacity)
            .expireAfterAccess(expirationInterval, TimeUnit.SECONDS)
            .removalListener(LOGGING_AUTOEVICTION_ONLY_REMOVAL_LISTENER)
            .build();

My removal listener is, as the name implies:

private static final RemovalListener<MyKey, MyRecord>  LOGGING_AUTOEVICTION_ONLY_REMOVAL_LISTENER
        = new RemovalListener<MyKey, MyRecord>() {
            @Override
            public void onRemoval(RemovalNotification<MyKey, MyRecord objectObjectRemovalNotification) {
                if (objectObjectRemovalNotification.wasEvicted()) {
                    log.debug("Entry evicted from cache: {} - Reason: {}", objectObjectRemovalNotification, objectObjectRemovalNotification.getCause());
                }
            }
        };

Finally, I only ever get entries to my cache, using get(K key, Callable<? extends V> valueLoader)

Here’s the problem: with the above code, I am seeing the following log output:

19:08:03.287 DEBUG [MyCache] - Entry evicted from cache: MyKey[123]=MyRecord@43ee148b - Reason: SIZE

Why are records being evicted from my cache when I didn’t use maximumSize() in the CacheBuilder invocation? I suspect it has something to do with “weight.” If so, what do I need to know about maxWeight() to not have cache entries evicted before the expiration time?

NOTE I’m aware of Caches Explained on the Google Guava site.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:20:16+00:00Added an answer on June 5, 2026 at 6:20 pm

    Is it possible that your expirationInterval is accidentally equal to zero? As expireAfterAccess documents, “When duration is zero, this method hands off to maximumSize(0).”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
I'm using Google Guava r08 and JDK 1.6.0_23. I want to create an ImmutableSortedMap
I am having trouble using the MapMaker from google-guava. Here is the code: package
Before using google collections I had something similar to next code: private Set<A> aSet
Using the new collections from Google's Guava, http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained How do I loop over a
I was using com.google.common.collect.PrimitiveArrays from Google Collections, however I cannot find it in Guava,
I'm using Guava-05-snapshot, with Sun's JDK 1.6 The code blows up executing this snippet:
Using Google Checkout, I'm able to estimate tax based on the zip code that's
Without using Google Checkout, I would like to provide a link that allows a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.