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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:22:53+00:00 2026-05-31T04:22:53+00:00

As I undestand this is LRU cache realization: // LRU cache —————————————————————– private static

  • 0

As I undestand this is LRU cache realization:

// LRU cache -----------------------------------------------------------------
private static final Map cacheLRU = Collections.synchronizedMap(new LinkedHashMap(MAX, 0.75f, 
        true/*true for access-order, false for insertion-order.*/) {
    protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
        return size() > MAX;
    };
});

static void cacheLRUTest(){
    cacheLRU.put ("1", "one");                           // 1
    cacheLRU.put ("2", "two");                           // 2 1
    cacheLRU.put ("3", "three");                         // 3 2 1
    cacheLRU.put ("4", "four");                          // 4 3 2
       if (cacheLRU.get("2") == null) throw new Error();    // 2 4 3
       cacheLRU.put ("5", "five");                          // 5 2 4
       cacheLRU.put ("4", "second four");                   // 4 5 2
       // Verify cache content.
       if (cacheLRU.size() != 3)              throw new Error();
       if (!cacheLRU.get("4").equals("second four")) throw new Error();
       if (!cacheLRU.get("5").equals("five"))        throw new Error();
       if (!cacheLRU.get("2").equals("two"))         throw new Error();

}

How can I realize MRU cache algorithm using LinkedHashMap?

UPDATE:

http://javalandscape.blogspot.com/2009/01/cachingcaching-algorithms-and-caching.html

As I undestand: LRU – If cache is full I need to delete lru item, MRU – … mru item

  • 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-31T04:22:55+00:00Added an answer on May 31, 2026 at 4:22 am

    ok, my apologies – i didn’t even know MRU was a valid hashing scheme, so sorry for my original comment on the question.

    anyway, all you need to do to implement one with LinkedHashMap is to store items in the map and, when that number will cross some limit, discard the most recent. you can do that easily because LinkedHashMap includes a record of the access order. so you need to do two things:

    1. create the LinkedHashMap with the constructor that allows you to specify the ordering mode, and request access order (since you want ordering to reflect access as well as addition).

    2. on insertion, when the size is at the limit, find the first key in the list via the iterator over keys, and remove it.

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

Sidebar

Related Questions

I'm new in this domain and like to write an application managing genealogical data.
This is more a theoretical question than a practical one, but given I undestand
I want to use map mechanism, based on property attribute marking, like this: [AttributeUsage(AttributeTargets.Property
I found this one: http://tiny-cobol.sourceforge.net/download.php Not sure to undestand how to install it on
I need to know this differences in order to undestand how to use them
I understand this is a subjective question but I want to see how others
I understand this code calculates the sum of the args of a variable, however,
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
If I understand this correctly: Current CPU developing companies like AMD and Intel have
While I understand this question is fairly vague since I'm not giving you all

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.