Skip to content

KobeFeng/n-way-set-associative-cache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

N-way Set Associative Cache

Java CI with Gradle

Basic implementation of a generic N-way Set Associative Cache using Java

Comes with 3 basic Cache Replacement policy implementations:

  1. Least Recently Used (LRU)
  2. Most Recently Used(MRU)
  3. Least Frequently Used (LFU)

To run the test suite - just go into the project root and type ./gradlew test

To use in your code, NWaySetAssociativeCache is supplied with Set Size, Entry Size and a Replacement Algorithm:

NWaySetAssociativeCache(int setSize, 
                        int entrySize, 
                        ReplacementAlgorithm<K, V, M> replacementAlgorithm)

Example:

Cache<Integer, String, Long> cache = 
    new NWaySetAssociativeCache<>(8, 2, new LruReplacementAlgorithm<>());
cache.put(16, "Good");
cache.put(16, "Bad");
String value  = cache.get(16); // value == "Bad"

To use a custom Cache Replacement Algorithm, implement the ReplacementAlgorithm interface and supply it into the NWaySetAssociativeCache:

public interface ReplacementAlgorithm<K,V,M> 
                    extends Comparator<CacheElement<K,V,M>>

To integrate with other typical caches, NWaySetAssociativeCache implements a basic Cache interface:

public interface Cache<K, V, M> {
       V get(final K key);
       void put(final K key, final V value);
}

About

N-way Set Associative Cache

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 60.0%
  • Groovy 40.0%