8000 GitHub - jolros/JavaLRUCache
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jolros/JavaLRUCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache

Some code I did while studying for tech interviews. It should be able to do all cache operations in O(1) time.

Some of this depends on the efficiency of the underlying HashMap data structure, which makes up half of the magic.

Usage:

public static class UserRetriever implements CacheRetriever<Long, User> {
        
    public User retrieve( Long id ) {
        // Expensive operation
    }
}
    
public void viewUser( long userId  ) {
    UserRetriever retriever = new UserRetriever();
    Cache<Long,String> cache = new Cache<Long,String>( 50, retriever);
    User user = cache.retrieve( userId );
    render(user);
}

This isn't intended to replace or augment a production data retrieval layer, it's just a thought exercise.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0