Use nested caches for enormous placements instead of weak hash map
Should recycle memory better
This commit is contained in:
parent
cc456958e1
commit
44b0bcd776
@ -66,20 +66,22 @@ class EnormousPlacement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val level2cache = WeakHashMap<WorldGenLevel, Cache<ChunkPos, GeneratedChunk>>()
|
private val level2cache = Caffeine.newBuilder()
|
||||||
private val lock = ReentrantLock()
|
.scheduler(Scheduler.systemScheduler())
|
||||||
|
.executor(Util.backgroundExecutor())
|
||||||
|
.expireAfterAccess(Duration.ofMinutes(10))
|
||||||
|
.weakKeys()
|
||||||
|
.build<WorldGenLevel, Cache<ChunkPos, GeneratedChunk>>()
|
||||||
|
|
||||||
private fun getCache(level: WorldGenLevel): Cache<ChunkPos, GeneratedChunk> {
|
private fun getCache(level: WorldGenLevel): Cache<ChunkPos, GeneratedChunk> {
|
||||||
return lock.withLock {
|
return level2cache.get(level) {
|
||||||
level2cache.computeIfAbsent(level) {
|
Caffeine.newBuilder()
|
||||||
Caffeine.newBuilder()
|
.scheduler(Scheduler.systemScheduler())
|
||||||
.scheduler(Scheduler.systemScheduler())
|
.executor(Util.backgroundExecutor())
|
||||||
.executor(Util.backgroundExecutor())
|
.maximumSize(16384L)
|
||||||
.maximumSize(16384L)
|
.expireAfterWrite(Duration.ofMinutes(5))
|
||||||
.expireAfterWrite(Duration.ofMinutes(5))
|
.softValues()
|
||||||
.softValues()
|
.build()
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user