Menu

Result Cache Meta Extensions

PHPStan invalidates the result cache based on changes in analysed files.

But sometimes the project setup or custom extensions are so complex, the result cache invalidation mechanism cannot invalidate the cache properly and it becomes stale.

Available in PHPStan 2.1.2

You can implement ResultCacheMetaExtension interface which returns a hash:

interface ResultCacheMetaExtension
{
	/**
	 * Returns unique key for this result cache meta entry. This describes the source of the metadata.
	 */
	public function getKey(): string;
	/**
	 * Returns hash of the result cache meta entry. This represents the current state of the additional meta source.
	 */
	public function getHash(): string;
}

The implementation needs to be registered in your configuration file:

services:
	-
		class: MyApp\PHPStan\ResultCacheMetaExtension
		tags:
			- phpstan.resultCacheMetaExtension

If the returned hash changes between runs, the result cache is completely invalidated and the project is analysed fully from scratch.

Edit this page on GitHub

Theme
A
© 2016–2025 Ondřej Mirtes