Added doc and changed accessibility of support class.

This commit is contained in:
Harrison Deng 2020-04-28 17:35:08 -05:00
parent 7a2a2d4ca6
commit e7f5558aa5
2 changed files with 11 additions and 1 deletions

View File

@ -22,6 +22,13 @@ public class Cache<K, V> {
this(1024);
}
/**
* Sets the value with the respective associated key.
* If the addition of this value and key cause the cache to be bigger than its designated max size,
* It will remove one of the least used values in the cache to accomodate.
* @param key The key to associate with the value.
* @param value The value to store.
*/
public void set(K key, V value) {
writeLock.lock();
try {
@ -62,6 +69,9 @@ public class Cache<K, V> {
return value.value;
}
/**
* Clears the cache of all values.
*/
public void clearCache() {
writeLock.lock();
try {

View File

@ -2,7 +2,7 @@ package ca.recrown.islandsurvivalcraft.caching;
import java.util.concurrent.locks.ReentrantLock;
public class UsageStack<K, V> {
class UsageStack<K, V> {
private volatile CacheValue<K, V> first, last;
private final ReentrantLock lock = new ReentrantLock();