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 6644075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:07:31+00:00 2026-05-26T00:07:31+00:00

I am building a cache that has to store as much data as possible.

  • 0

I am building a cache that has to store as much data as possible. CPU is not a mayor issue, because the next level of data is a lot more expessive to reach than running the CPUs a little bit for decompression.

I’m looking for a good strategy and not a full implemenation. A typical object instance that should be cached can be gernalized as a list of hashmaps. The keys in these map are very similiar to keys in another map in that list. Keys and values are strings.

Maps in different caching objects (this means also different lists) may not always have similar keys. Maybe only a subset (50%) of the keys is the same.

I was thinking of extracting the keys into ONE header array and each collection of values of the hashmap into another array with the same length. This means the data array might be sparse (null-pointers). But I don’t have to carry the meta data around. The possition in the data array is the only way of looking up the correct key.

Now I want to compress the data array. Compression won’t really work well on a single data array because there is little information. It will need a few data arrays stuck together to get a good compression rate.

Is there any good way of compressing String-Arrays in java? How many of these data arrays should I cluster for good results?

Is there maybe some better aporoach? This is a open questions for collecting ideas, so please feel free to elaborate 🙂

  • 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-05-26T00:07:31+00:00Added an answer on May 26, 2026 at 12:07 am

    Flyweight can help

    If are not compressing you can use Flyweight pattern to avoid the cost of the string-key repeated in each object.

    Remember a string is an object so a key in your hashmap is a reference to it. If a lot of objects with the same property use references to the same string object you only have 4-bytes for each reference and only one string in memory.

    How to ensure you are sharing the string objects between objects? You can use something similar to String.intern(). But please don’t use String.intern() itself.

    Interning a string is returning the same string-object for the same string value. You must hold a cache for those strings. The reason I don’t recommend String.intern() is that the cache is the String class itself so it nevers get freed. But you can implement something analogous.

    This code returns your own string if it’s new. And returns the first one if it’s not.

    HashMap<String,String> internedStrings = new HashMap<String,String>();
    
    syncrhonized String returnUniqueString(String str) {
       String alreadyCached = internedStrings.get(str);
       if (alreadyCached == null) {
          internedStrings.put(str, str);
          alreadyCached = str;
       }
       return alreadyCached;
    }
    

    But if you are compressing, not

    Because compressing means you are serializing your object graphs and each property name will be serialized as a different string, so repeating itself. Maybe the compressed size doesn’t grow too much because it’s a repeated string but when you rehidrate the objects they will be created separately.

    Maybe you can use the returnUniqueString at the time of rehidrating 🙂

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

Sidebar

Related Questions

We are currently thinking of building a cache-system to hold data pulled out of
building a site using PHP and MySQL that needs to store a lot of
Building a website that has English & Japanese speaking users, with the Japanese users
I created a simple Caching Data Access Layer that has caching using the Enterprise
I'm building an app that has several different sections to it, all of which
I am building a webapp that has the following characteristics: It only has a
I'm building an application in Python2.6 that needs to get data from CouchDb. I'm
Building on what has been written in SO question Best Singleton Implementation In Java
Building a Django app on a VPS. I am not very experienced with setting
I'm building a Javascript application and eash user has an individual UserSession. The application

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.