Files
fastmovieai/fastmovie-admin/plugin/control/utils/LRUCache.php
T
李建琦 eae151fd57 FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0)
- 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION
- vendor/示例资源已gitignore
2026-08-26 18:37:36 +08:00

44 lines
979 B
PHP

<?php
namespace plugin\control\utils;
class LRUCache
{
private int $capacity;
private array $cache = [];
private array $order = [];
public function __construct($capacity = 2000)
{
$this->capacity = $capacity;
}
public function get($key)
{
if (!isset($this->cache[$key])) {
return null;
}
unset($this->order[$key]);
$this->order[$key] = true;
return $this->cache[$key];
}
public function set($key, $value)
{
if (isset($this->cache[$key])) {
$this->cache[$key] = $value;
unset($this->order[$key]);
$this->order[$key] = true;
return;
}
if (count($this->cache) >= $this->capacity) {
$oldestKey = array_key_first($this->order);
unset($this->cache[$oldestKey], $this->order[$oldestKey]);
}
$this->cache[$key] = $value;
$this->order[$key] = true;
}
}