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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:57:11+00:00 2026-05-11T07:57:11+00:00

What would be the best way to implement a most-recently-used cache of objects? Here

  • 0

What would be the best way to implement a most-recently-used cache of objects?

Here are the requirements and restrictions…

  • Objects are stored as key/value Object/Object pairs, so the interface would be a bit like Hashtable get/put
  • A call to ‘get’ would mark that object as the most recently used.
  • At any time, the least recently used object can be purged from the cache.
  • Lookups and purges must be fast (As in Hashtable fast)
  • The number of Objects may be large, so list lookups are not good enough.
  • The implementation must be made using JavaME, so there is little scope for using third-party code or neat library classes from the standard Java libraries. For this reason I’m looking more for algorithmic answers rather than recommendations of off-the-peg solutions.
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T07:57:12+00:00Added an answer on May 11, 2026 at 7:57 am

    Java Collections provide LinkedHashMap out of the box, which is well-suited to building caches. You probably don’t have this in Java ME, but you can grab the source code here:

    http://kickjava.com/src/java/util/LinkedHashMap.java.htm

    If you can’t just copy-paste it, looking at it should get you started implementing one for inclusion in your mobile app. The basic idea is just to include a linked list through the map elements. If you keep this updated whenever someone does put or get, you can efficiently track access order and use order.

    The docs contain instructions for building an MRU Cache by overriding the removeEldestEntry(Map.Entry) method. All you really have to do is make a class that extends LinkedHashMap and override the method like so:

    private static final int MAX_ENTRIES = 100;  protected boolean removeEldestEntry(Map.Entry eldest) {    return size() > MAX_ENTRIES; } 

    There’s also a constructor that lets you specify whether you want the class to store things in order by insertion or by use, so you’ve got a little flexibility for your eviction policy, too:

    public LinkedHashMap(int initialCapacity,                      float loadFactor,                      boolean accessOrder) 

    Pass true for use-order and false for insertion order.

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

Sidebar

Ask A Question

Stats

  • Questions 268k
  • Answers 268k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Make sure every image in every row has the same… May 13, 2026 at 1:00 pm
  • Editorial Team
    Editorial Team added an answer If your client doesn't trust you, there's nothing you can… May 13, 2026 at 1:00 pm
  • Editorial Team
    Editorial Team added an answer You can try querying the inLiveResize method from the content… May 13, 2026 at 1:00 pm

Related Questions

I have a list of books obtained from the database. When a user selects
What's the best way to implement user controls that require AJAX callbacks? I want
I searched the web for different solutions to the n-queens problem in Haskell but
I've been diving into Erlang recently, and I decided to use Mnesia to do

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.