Skip to content

Commit

Permalink
Integrate change from EngineHub/WorldEdit#1862
Browse files Browse the repository at this point in the history
  • Loading branch information
gtosh4 committed Jul 18, 2023
1 parent 647e346 commit 238a57e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/java/com/sk89q/worldedit/session/request/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import javax.annotation.Nullable;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.world.World;
Expand All @@ -27,13 +30,9 @@
*/
public final class Request {

private static final ThreadLocal<Request> threadLocal = new ThreadLocal<Request>() {

@Override
protected Request initialValue() {
return new Request();
}
};
private static final LoadingCache<Thread, Request> THREAD_TO_REQUEST = CacheBuilder.newBuilder()
.weakKeys()
.build(CacheLoader.from(Request::new));

private @Nullable World world;
private @Nullable LocalSession session;
Expand Down Expand Up @@ -101,13 +100,13 @@ public void setEditSession(@Nullable EditSession editSession) {
* @return the current request
*/
public static Request request() {
return threadLocal.get();
return THREAD_TO_REQUEST.getUnchecked(Thread.currentThread());
}

/**
* Reset the current request and clear all fields.
*/
public static void reset() {
threadLocal.remove();
THREAD_TO_REQUEST.invalidate(Thread.currentThread());
}
}

0 comments on commit 238a57e

Please sign in to comment.