com.launchdarkly.client.SimpleLRUCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of launchdarkly-client Show documentation
Show all versions of launchdarkly-client Show documentation
Official LaunchDarkly SDK for Java
package com.launchdarkly.client;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* A very basic implementation of a LRU cache with a fixed capacity. Note that in this
* implementation, entries only become new again when written, not when read.
* See: http://chriswu.me/blog/a-lru-cache-in-10-lines-of-java/
*/
@SuppressWarnings("serial")
class SimpleLRUCache extends LinkedHashMap {
private final int capacity;
SimpleLRUCache(int capacity) {
super(16, 0.75f, true);
this.capacity = capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > capacity;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy