Package com.rvandoosselaer.blocks
Class ChunkCache
- java.lang.Object
-
- com.rvandoosselaer.blocks.ChunkCache
-
- All Implemented Interfaces:
ChunkResolver
public class ChunkCache extends java.lang.Object implements ChunkResolver
An in memory threadsafe chunk cache implementation.
-
-
Constructor Summary
Constructors Constructor Description ChunkCache()ChunkCache(int cacheSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidevict(@NonNull com.simsilica.mathd.Vec3i location)voidevictAll()java.util.Optional<Chunk>get(@NonNull com.simsilica.mathd.Vec3i location)Return a Chunk optional.ChunkgetChunk(@NonNull com.simsilica.mathd.Vec3i location)Return the chunk at the given location or null.longgetSize()voidmaintain()By default, Caffeine does not perform cleanup and evict values "automatically" or instantly after a value expires.voidput(@NonNull Chunk chunk)
-
-
-
Method Detail
-
get
public java.util.Optional<Chunk> get(@NonNull @NonNull com.simsilica.mathd.Vec3i location)
Description copied from interface:ChunkResolverReturn a Chunk optional.- Specified by:
getin interfaceChunkResolver- Parameters:
location- of the chunk- Returns:
- chunk
-
getChunk
public Chunk getChunk(@NonNull @NonNull com.simsilica.mathd.Vec3i location)
Description copied from interface:ChunkResolverReturn the chunk at the given location or null.- Specified by:
getChunkin interfaceChunkResolver- Parameters:
location- of the chunk- Returns:
- chunk or null
-
evict
public void evict(@NonNull @NonNull com.simsilica.mathd.Vec3i location)
-
evictAll
public void evictAll()
-
put
public void put(@NonNull @NonNull Chunk chunk)
-
getSize
public long getSize()
-
maintain
public void maintain()
By default, Caffeine does not perform cleanup and evict values "automatically" or instantly after a value expires. Instead, it performs small amounts of maintenance work after write operations or occasionally after read operations if writes are rare. If your cache is high-throughput then you don't have to worry about performing cache maintenance to clean up expired entries and the like. If your cache is read and written to rarely, you may wish to leverage an external thread, that calls Cache.cleanUp() when appropriate.
-
-