Skip to main content

test task Junior java

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-12-02

Hello guys!

ive been sent the following task:

Create a configurable two-level cache (for caching Objects). Level 1 is memory, level 2 is filesystem. Config params should let one specify the cache strategies and max sizes of level 1 and level 2.

Could anybody explain me what exactly i should do, and what is the best strategy for it??

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-12-05

For the memory caching it basically means you're storing objects in memory. For example, you could have a HashMap which stores cached objects in memory that allows your system to quickly have access to those objects. A common example would be retrieving information from a database and storing it in a HashMap. Since database access is expensive you don't want to continuously access the database to retrieve information. Therefore, It makes more sense to store it in memory. However, memory isn't free so you need to limit the size of your HashMap.
There's different caching strategies available. One example of a caching strategy is LRU (Least Recently Used). With LRU when your cache map exceeds a certain size it removes the least recently used entry in the map. Thats not always the best strategy. The strategy to use really depends on the situation. Anyway, I'll leave the Level 2 caching up for you to think about, but I think you get the general idea.
I actually plan to discuss caching strategies in the future in my tech blog on Java, which you can find here: