2018-10-12 05:00:32 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-11-12 16:57:05 +01:00
|
|
|
namespace Psalm\Tests\Internal\Provider;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Internal\Provider\FileStorageCacheProvider;
|
2018-10-12 05:00:32 +02:00
|
|
|
use Psalm\Storage\FileStorage;
|
2021-06-08 04:55:21 +02:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use function strtolower;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
class FileStorageInstanceCacheProvider extends FileStorageCacheProvider
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
2020-12-29 12:42:12 +01:00
|
|
|
/** @var array<lowercase-string, FileStorage> */
|
2022-12-16 19:58:47 +01:00
|
|
|
private array $cache = [];
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-24 04:35:26 +02:00
|
|
|
/**
|
|
|
|
* @param lowercase-string $file_path
|
|
|
|
*/
|
|
|
|
protected function storeInCache(string $file_path, FileStorage $storage): void
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
$this->cache[$file_path] = $storage;
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function removeCacheForFile(string $file_path): void
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
unset($this->cache[strtolower($file_path)]);
|
|
|
|
}
|
|
|
|
|
2023-06-24 04:35:26 +02:00
|
|
|
/**
|
|
|
|
* @param lowercase-string $file_path
|
|
|
|
*/
|
|
|
|
protected function loadFromCache(string $file_path): ?FileStorage
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
2023-06-24 04:35:26 +02:00
|
|
|
return $this->cache[$file_path] ?? null;
|
2018-10-12 05:00:32 +02:00
|
|
|
}
|
|
|
|
}
|