Skip to content

Commit 4f8eafa

Browse files
authored
Merge pull request #347 from hostep/make-cache-key-unique-per-project
Make cache key unique per project (so per current working directory).
2 parents 847feba + dca5d22 commit 4f8eafa

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎extension.neon‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ services:
6565
class: bitExpert\PHPStan\Magento\Autoload\Cache\FileCacheStorage
6666
arguments:
6767
directory: %tmpDir%/cache/PHPStan
68+
magentoRoot: %magento.magentoRoot%
6869
autoloaderCache:
6970
autowired: false
7071
class: PHPStan\Cache\Cache

‎src/bitExpert/PHPStan/Magento/Autoload/Cache/FileCacheStorage.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ class FileCacheStorage implements CacheStorage
2121
*/
2222
private $directory;
2323

24+
/**
25+
* @var string
26+
*/
27+
private $magentoRoot;
28+
2429
/**
2530
* FileCacheStorage constructor.
2631
*
2732
* @param string $directory
2833
*/
29-
public function __construct(string $directory)
34+
public function __construct(string $directory, string $magentoRoot)
3035
{
3136
$this->directory = $directory;
37+
$this->magentoRoot = $magentoRoot;
3238
}
3339

3440
/**
@@ -73,7 +79,7 @@ public function save(string $key, string $variableKey, $data): void
7379
*/
7480
private function getCacheDir(string $key): string
7581
{
76-
$keyHash = sha1($key);
82+
$keyHash = sha1(sprintf('%s/%s', $this->magentoRoot, $key));
7783
$firstDirectory = sprintf('%s/%s', $this->directory, substr($keyHash, 0, 2));
7884
return sprintf('%s/%s', $firstDirectory, substr($keyHash, 2, 2));
7985
}

0 commit comments

Comments
 (0)