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

  • SEARCH
  • Home
  • 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 7771125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:34:19+00:00 2026-06-01T16:34:19+00:00

I would like to have several Cache objects in my application and I’d like

  • 0

I would like to have several Cache objects in my application and I’d like them to share a maximum weight. So given some total weight X, I’d like the sum of the weights of the cached items across all my caches to not exceed X. I don’t know how many caches will be needed up front, nor do the caches need to be ‘fair’ — if one is heavily used while others are not, it should be able to take the lion’s share of the global maximum. I don’t want misses on a cache because its considered full while other caches are mostly un-used and that space could be allocated by the heavily used cache. These will be keeping me from going back to disk to get data, so low miss rates are important.

I thought about having a Weigher implementation that used a static variable that kept the total cached weight. Then a Weigher would return the weight of the object, if that weight is less than the total remaining space, I’d return the weight as-is. If it’s more than the total weight left, I could return Long.MAX_VALUE so the item is not cached. Each cache would have a high maximum weight, probably Long.MAX_VALUE-1 so that an element can always be inserted as long as we can calculate/allocate a weight for it.

The problem is that I don’t see any way to know the total weight of cached objects. I could decrement the total weight w/ eviction listeners, but there’s no way that I can see to be notified when something gets inserted into the cache, nor do the cache stats reflect this in their data.

Is there any workaround for this or approach I could take to achieve this functionality? I have a custom cache implementation that handles global weights, but lacks many of the features provided by the Guava cache, so I’d like to avoid re-implementing stuff if possible. Though I don’t mind trying to wire this into the Guava Cache if you can point me in a general direction.

  • 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-01T16:34:21+00:00Added an answer on June 1, 2026 at 4:34 pm

    The Guava caches do not interact with each other at all — there’s no “global” interaction — but softValues() is the traditional way to make “memory-sensitive” caches, since soft references are collected by the GC (typically in globally least-recently-used order), but only when memory is tight.

    I don’t even believe Guava caches internally keep track of their total weight — they track total weight on a per-segment basis, I believe, but keeping track of the total weight would require too much locking.

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

Sidebar

Related Questions

I have several PDF templates that I would like to load and modify and
I have several ASP.NET sites in IIS7 and would like to be able to
I have several python.exe processes running on my Vista machine and I would like
I have several windows machines identified by ip address. I would like to write
I have several constant defined for a webservice, and I would like to make
I have several images stored in content://media/external/images/media. I would like to display by using
I have several dropdowns on the page one under another, and would like to
I have an app that have several views. In one view I would like
I have a Controls.Canvas with several shapes on it and would like to add
I have a directory with several .html files. Would like to read the list

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.