1. Learn
  2. /
  3. Courses
  4. /
  5. Optimizing Code in Java

Connected

Exercise

Implementing an LRU cache

You're developing a web application that frequently retrieves user profile information as strings. To improve performance, you want to implement a simple cache that stores these profile strings and can identify which entries were least recently used.

The CacheEntry class was preloaded for you.

Instructions

100 XP
  • In the get() method, retrieve the cache entry for the specified key.
  • After retrieving the key, update its access time.
  • After putting an entry in the cache, if the capacity has been exceeded, remove the least recently used entry.