Skip to content

Commit

Permalink
Invalid whole cache on file change in Ecotone Lite (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgafka authored Dec 7, 2024
1 parent 92981d3 commit 10dade3
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions packages/Ecotone/src/Lite/EcotoneLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,11 @@ public static function bootstrapFlowTestingWithEventStore(

private static function getFileNameBasedOnConfig(
string $pathToRootCatalog,
bool $useCachedVersion,
FileSystemAnnotationFinder $annotationFinder,
ServiceConfiguration $serviceConfiguration,
array $configurationVariables,
bool $enableTesting
): string {
if ($useCachedVersion) {
return 'messaging';
}

// this is temporary cache based on if files have changed
// get file contents based on class names, configuration and configuration variables
$fileSha = '';
Expand Down Expand Up @@ -236,16 +231,8 @@ private static function prepareConfiguration(ContainerInterface|array $container
}

$externalContainer = $containerOrAvailableServices instanceof ContainerInterface ? $containerOrAvailableServices : InMemoryPSRContainer::createFromAssociativeArray($containerOrAvailableServices);

$serviceCacheConfiguration = new ServiceCacheConfiguration(
$serviceConfiguration->getCacheDirectoryPath(),
self::shouldUseAutomaticCache($useCachedVersion, $pathToRootCatalog),
);
$configurationVariableService = InMemoryConfigurationVariableService::create($configurationVariables);
$definitionHolder = null;
$messagingSystemCachePath = null;

$serviceConfiguration = MessagingSystemConfiguration::addCorePackage($serviceConfiguration, $enableTesting);

$annotationFinder = AnnotationFinderFactory::createForAttributes(
realpath($pathToRootCatalog),
$serviceConfiguration->getNamespaces(),
Expand All @@ -255,13 +242,19 @@ private static function prepareConfiguration(ContainerInterface|array $container
$classesToResolve,
$enableTesting
);
if ($serviceCacheConfiguration->shouldUseCache()) {
$messagingSystemCachePath = $serviceCacheConfiguration->getPath() . DIRECTORY_SEPARATOR . self::getFileNameBasedOnConfig($pathToRootCatalog, $useCachedVersion, $annotationFinder, $serviceConfiguration, $configurationVariables, $enableTesting);
$cacheHash = self::getFileNameBasedOnConfig($pathToRootCatalog, $annotationFinder, $serviceConfiguration, $configurationVariables, $enableTesting);
$serviceCacheConfiguration = new ServiceCacheConfiguration(
$serviceConfiguration->getCacheDirectoryPath() . DIRECTORY_SEPARATOR . $cacheHash,
self::shouldUseAutomaticCache($useCachedVersion, $pathToRootCatalog),
);

if (file_exists($messagingSystemCachePath)) {
/** It may fail on deserialization, then return `false` and we can build new one */
$definitionHolder = unserialize(file_get_contents($messagingSystemCachePath));
}
$configurationVariableService = InMemoryConfigurationVariableService::create($configurationVariables);
$definitionHolder = null;
$messagingSystemCachePath = $serviceCacheConfiguration->getPath() . DIRECTORY_SEPARATOR . 'messaging';

if ($serviceCacheConfiguration->shouldUseCache() && file_exists($messagingSystemCachePath)) {
/** It may fail on deserialization, then return `false` and we can build new one */
$definitionHolder = unserialize(file_get_contents($messagingSystemCachePath));
}

if (! $definitionHolder) {
Expand Down

0 comments on commit 10dade3

Please sign in to comment.