mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Make file storage cache handling consistent
This commit is contained in:
parent
9939cae52d
commit
1b1915eaf5
@ -19,30 +19,24 @@ class FileStorageCacheProvider extends InternalFileStorageCacheProvider
|
||||
{
|
||||
}
|
||||
|
||||
public function writeToCache(FileStorage $storage, string $file_contents): void
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function storeInCache(string $file_path, FileStorage $storage): void
|
||||
{
|
||||
$file_path = strtolower($storage->file_path);
|
||||
$this->cache[$file_path] = $storage;
|
||||
}
|
||||
|
||||
public function getLatestFromCache(string $file_path, string $file_contents): ?FileStorage
|
||||
{
|
||||
$cached_value = $this->loadFromCache(strtolower($file_path));
|
||||
|
||||
if (!$cached_value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $cached_value;
|
||||
}
|
||||
|
||||
public function removeCacheForFile(string $file_path): void
|
||||
{
|
||||
unset($this->cache[strtolower($file_path)]);
|
||||
}
|
||||
|
||||
private function loadFromCache(string $file_path): ?FileStorage
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function loadFromCache(string $file_path): ?FileStorage
|
||||
{
|
||||
return $this->cache[strtolower($file_path)] ?? null;
|
||||
return $this->cache[$file_path] ?? null;
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +64,17 @@ class FileStorageCacheProvider
|
||||
public function writeToCache(FileStorage $storage, string $file_contents): void
|
||||
{
|
||||
$file_path = strtolower($storage->file_path);
|
||||
$cache_location = $this->getCacheLocationForPath($file_path, true);
|
||||
$storage->hash = $this->getCacheHash($file_path, $file_contents);
|
||||
|
||||
$this->storeInCache($file_path, $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function storeInCache(string $file_path, FileStorage $storage): void
|
||||
{
|
||||
$cache_location = $this->getCacheLocationForPath($file_path, true);
|
||||
$this->cache->saveItem($cache_location, $storage);
|
||||
}
|
||||
|
||||
@ -107,7 +115,10 @@ class FileStorageCacheProvider
|
||||
return PHP_VERSION_ID >= 8_01_00 ? hash('xxh128', $data) : hash('md4', $data);
|
||||
}
|
||||
|
||||
private function loadFromCache(string $file_path): ?FileStorage
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function loadFromCache(string $file_path): ?FileStorage
|
||||
{
|
||||
$storage = $this->cache->getItem($this->getCacheLocationForPath($file_path));
|
||||
if ($storage instanceof FileStorage) {
|
||||
|
@ -16,30 +16,24 @@ class FileStorageInstanceCacheProvider extends FileStorageCacheProvider
|
||||
{
|
||||
}
|
||||
|
||||
public function writeToCache(FileStorage $storage, string $file_contents): void
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function storeInCache(string $file_path, FileStorage $storage): void
|
||||
{
|
||||
$file_path = strtolower($storage->file_path);
|
||||
$this->cache[$file_path] = $storage;
|
||||
}
|
||||
|
||||
public function getLatestFromCache(string $file_path, string $file_contents): ?FileStorage
|
||||
{
|
||||
$cached_value = $this->loadFromCache(strtolower($file_path));
|
||||
|
||||
if (!$cached_value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $cached_value;
|
||||
}
|
||||
|
||||
public function removeCacheForFile(string $file_path): void
|
||||
{
|
||||
unset($this->cache[strtolower($file_path)]);
|
||||
}
|
||||
|
||||
private function loadFromCache(string $file_path): ?FileStorage
|
||||
/**
|
||||
* @param lowercase-string $file_path
|
||||
*/
|
||||
protected function loadFromCache(string $file_path): ?FileStorage
|
||||
{
|
||||
return $this->cache[strtolower($file_path)] ?? null;
|
||||
return $this->cache[$file_path] ?? null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user