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 void
evict(@NonNull com.simsilica.mathd.Vec3i location)
void
evictAll()
java.util.Optional<Chunk>
get(@NonNull com.simsilica.mathd.Vec3i location)
Return a Chunk optional.Chunk
getChunk(@NonNull com.simsilica.mathd.Vec3i location)
Return the chunk at the given location or null.long
getSize()
void
maintain()
By default, Caffeine does not perform cleanup and evict values "automatically" or instantly after a value expires.void
put(@NonNull Chunk chunk)
-
-
-
Method Detail
-
get
public java.util.Optional<Chunk> get(@NonNull @NonNull com.simsilica.mathd.Vec3i location)
Description copied from interface:ChunkResolver
Return a Chunk optional.- Specified by:
get
in interfaceChunkResolver
- Parameters:
location
- of the chunk- Returns:
- chunk
-
getChunk
public Chunk getChunk(@NonNull @NonNull com.simsilica.mathd.Vec3i location)
Description copied from interface:ChunkResolver
Return the chunk at the given location or null.- Specified by:
getChunk
in 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.
-
-