Made sure occurrences are properly tracked.
This commit is contained in:
		| @@ -26,7 +26,7 @@ public class Cache<Key, Value> { | |||||||
|                 while (occurrences.get(occurrenceOrder.peek()) > 1) { |                 while (occurrences.get(occurrenceOrder.peek()) > 1) { | ||||||
|                     occurencesTrackedPoll(); |                     occurencesTrackedPoll(); | ||||||
|                 } |                 } | ||||||
|                 data.remove(occurrenceOrder.poll()); |                 data.remove(occurencesTrackedPoll()); | ||||||
|             } |             } | ||||||
|             occurrencesTrackedAdd(key); |             occurrencesTrackedAdd(key); | ||||||
|         } |         } | ||||||
| @@ -63,12 +63,12 @@ public class Cache<Key, Value> { | |||||||
|      * @param key the key associated with the value. |      * @param key the key associated with the value. | ||||||
|      * @return the value associated to the key. |      * @return the value associated to the key. | ||||||
|      */ |      */ | ||||||
|     public Value getValue(Key key) { |     public synchronized Value getValue(Key key) { | ||||||
|         occurrencesTrackedAdd(key); |         occurrencesTrackedAdd(key); | ||||||
|         return data.get(key); |         return data.get(key); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void clearCache() { |     public synchronized void clearCache() { | ||||||
|         data.clear(); |         data.clear(); | ||||||
|         occurrenceOrder.clear(); |         occurrenceOrder.clear(); | ||||||
|         occurrences.clear(); |         occurrences.clear(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user