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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:51:10+00:00 2026-06-09T16:51:10+00:00

I am working on a web-based medical application and need to create a small

  • 0

I am working on a web-based medical application and need to create a small in-memory object cache. Here is my use-case.

We need to show list of requests submitted by people who need certain things (Blood, Kidney, etc.) and it’s not going to be a huge list as in a given day request for blood or anything else will be a limited one. Please take into account that we do not want to use any caching API as it would be an overkill. The idea is to create a Map and place it in the ApplicationContext.

The moment a new request is being placed by any person, we will update that Map in the Application context and the moment the request expires, we will remove them from the Map. We need to look into the following points additionally.

  1. Need to set Max Element Limit.
  2. If Max Limit reached, we should removed entry which was added first.
  3. Take care of any Synchronized issues.

Please suggest what Data-structure should be used and what things to take care of while implementing this.

  • 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-09T16:51:11+00:00Added an answer on June 9, 2026 at 4:51 pm

    I believe LinkedHashMap is exactly what you need. You just need to override removeEldestEntry(…) method, and it will automatically remove old entries for you if the maximum capacity is reached. Something like:

    import java.util.*;
    
    class CacheMap<K,V> extends LinkedHashMap<K,V> {
        protected final int maxCapacity;
        public CacheMap(int maxCapacity) {
            this.maxCapacity = maxCapacity;
        }
    
        @Override
        protected boolean removeEldestEntry(Map.Entry eldest) {
            return size() > maxCapacity;
        }
    }
    

    You could implement a more sophisticated logic, for example remove very old entries even if the max. capacity is not reached.

    If synchronizing atomic map operations is enough for you, you can just wrap the map into Collections.synchronizedMap(…):

    Map<K,V> map = Collections.synchronizedMap(new CacheMap<K,V>(capacity));
    

    If you need more accurate synchronization, for example read the map and update it in one synchronized block, you need to synchronize (all) code blocks that work with the map yourself.

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

Sidebar

Related Questions

I'm working on a web-based business application where each customer will need to have
A brief background: I'm working on a web-based drawing application and need to draw
Here's the scenario, I am working on a web-based application develped used JSP/Servlet technique,
I am working on a web based application that will need to store usernames
I'm working on a web based application which uses a JSON over HTTP based
I'm working on a web-based application, and looking to integrate each user's e-mail (gmail,
The web-based application I’m currently working on is growing arms and legs! It’s basically
I'm working on a project that requires a Web-based workflow application. We're now evaluating
I'm working on a web based project where we make use of the user's
I am working on the development of a web based application on codeigniter. I

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.