Make MemoryManager aware of ChunkCache

This commit is contained in:
Dylan K. Taylor
2021-10-28 20:28:00 +01:00
parent eb40b741ae
commit 5db3915aad
2 changed files with 15 additions and 3 deletions

View File

@ -36,9 +36,6 @@ use function strlen;
/**
* This class is used by the current MCPE protocol system to store cached chunk packets for fast resending.
*
* TODO: make MemoryManager aware of this so the cache can be destroyed when memory is low
* TODO: this needs a hook for world unloading
*/
class ChunkCache implements ChunkListener{
/** @var self[][] */
@ -69,6 +66,19 @@ class ChunkCache implements ChunkListener{
return self::$instances[$worldId][$compressorId];
}
public static function pruneCaches() : void{
foreach(self::$instances as $compressorMap){
foreach($compressorMap as $chunkCache){
foreach($chunkCache->caches as $chunkHash => $promise){
if($promise->hasResult()){
//Do not clear promises that are not yet fulfilled; they will have requesters waiting on them
unset($chunkCache->caches[$chunkHash]);
}
}
}
}
}
/** @var World */
private $world;
/** @var Compressor */