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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:09:07+00:00 2026-06-11T17:09:07+00:00

I want to cache objects in memory. The requirements are as follows: Every record/object

  • 0

I want to cache objects in memory. The requirements are as follows:

  1. Every record/object is associated with a unique key.
  2. 400-500 records/objects to be stored. If the number of records increase beyond the specified limit, then the older records should be evicted.
  3. Records shouldn’t be stored beyond 2 mins.
  4. Should scale down when JVM is running out of memory (kind of weak reference).
  5. Third party library cannot be used because its a small module and the intention is just to decrease the unnecessary network access.
  6. There are more writes, less reads

Security is also a concern here because we are going to cache some sensitive data. This data will be cached in memory. Should I really worry about the security and encrypt the data?

I am looking for a Java class which provides a similar functionality.

Currently I am thinking of extending WeakHashMap, and implementing various private/public methods to adhere to the requirements.

If you have any other idea please share here.

  • 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-11T17:09:08+00:00Added an answer on June 11, 2026 at 5:09 pm

    You don’t want to use WeakHashMap. SoftHashMap would be closer but is not available in the standard library. If I were you I’ll look at Guava’s cache classes for hints.

    But here are some additional thoughts:

    Should scale down when JVM is running out of memory(kind of weak reference).

    You mean soft reference. But anyways, this requirement smells a bit to me. It can be a valid requirement I’d admit, but it’s rare that you really need this. If the size of your records can be reasonably well predicted and if you are planning to have a hard limit on number of records you want to cache, chances are that you don’t need this complexity.

    Third party library shouldn’t be use.

    Everybody mentioned this, and they’re right.

    On the security aspect, efficacy of encrypting data cached in-memory is dubious. You’ll have to have the encryption key in-memory as well. I bet there are many things to worry more than attackers reading your memory content.

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

Sidebar

Related Questions

I want to write method which generates key for cache object. This is my
I am creating an object pool to cache some recyclable objects in memory at
I'm creating a small cache daemon, and I want to limit its memory usage
If I have lots of objects that I want to cache how would I
I want to write a cache using SoftReference s using as much memory as
I want to cache query results so that the same results are fetched for
I want to cache data from a json-webservice in my android app. The first
I have a Rails app (running 3.2.2) and I want to cache my users'
I am using XSLT 1.0 and C# 2.0. and I want to cache my
Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache

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.