Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 494 Bytes

LRUCache.md

File metadata and controls

22 lines (16 loc) · 494 Bytes

缓存 LruCache

ini_set("memory_limit", "128M");

// 缓存算法(本地内存版)
$size = 500000;
$lruCache = new LruCacheHelper($size);

for ($i = 0; $i < $size; $i++) {
	$lruCache->set("k{$i}", str_repeat('1', 10));
}

$this->assertIsString((string)$lruCache->get('k1000'));
$this->assertEquals($size, $lruCache->count());

$lruCache->remove('k1');
$this->assertEquals($size - 1, $lruCache->count());

// 内存消耗 100MB左右
dump(Helper::system()::getMemoryUsage());