mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
parent
d9abe76531
commit
784935a975
2 changed files with 33 additions and 30 deletions
|
@ -72,10 +72,10 @@ public class Cache<K, V> {
|
|||
* @return the value to which the specified key is mapped, or null if no value is mapped for the key
|
||||
*/
|
||||
public V get(K key) {
|
||||
synchronized (internal) {
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
|
||||
synchronized (internal) {
|
||||
return internal.get(key);
|
||||
}
|
||||
}
|
||||
|
@ -87,10 +87,10 @@ public class Cache<K, V> {
|
|||
* @return true if a mapping exists for the specified key
|
||||
*/
|
||||
public boolean containsKey(K key) {
|
||||
synchronized (internal) {
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
|
||||
synchronized (internal) {
|
||||
return internal.containsKey(key);
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +101,10 @@ public class Cache<K, V> {
|
|||
* @param key key to invalidate
|
||||
*/
|
||||
public void invalidate(K key) {
|
||||
synchronized (internal) {
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
// Run lazy check to clean cache
|
||||
lazyCheck();
|
||||
|
||||
synchronized (internal) {
|
||||
if (!internal.containsKey(key)) {
|
||||
// Value either not present or cleaned by lazy check. Either way, we're good
|
||||
return;
|
||||
|
@ -143,27 +143,30 @@ public class Cache<K, V> {
|
|||
private void lazyCheck() {
|
||||
long now = System.currentTimeMillis();
|
||||
long nextExpiry = now + retention;
|
||||
for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<Long, K> entry = iterator.next();
|
||||
synchronized (internal) {
|
||||
for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator
|
||||
.hasNext();) {
|
||||
Map.Entry<Long, K> entry = iterator.next();
|
||||
|
||||
if (entry.getKey() > now) {
|
||||
break;
|
||||
if (entry.getKey() > now) {
|
||||
break;
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
|
||||
if (inUseCheck.run(internal.get(entry.getValue()))) {
|
||||
expiry.put(nextExpiry, entry.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
V value = internal.remove(entry.getValue());
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
postRemoval.run(value);
|
||||
}
|
||||
|
||||
iterator.remove();
|
||||
|
||||
if (inUseCheck.run(internal.get(entry.getValue()))) {
|
||||
expiry.put(nextExpiry, entry.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
V value = internal.remove(entry.getValue());
|
||||
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
postRemoval.run(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -74,7 +74,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
|
@ -98,7 +98,7 @@
|
|||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
|
|
Loading…
Reference in a new issue