Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: BUGFIX: Enable WorkspaceRuntimeCache and ContentSubgraphWithRuntimeCaches after disabling #4955

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -138,6 +138,7 @@ public function reset(): void
$this->getDatabaseConnection()->exec('TRUNCATE ' . $this->tableName);
$this->checkpointStorage->acquireLock();
$this->checkpointStorage->updateAndReleaseLock(SequenceNumber::none());
$this->workspaceRuntimeCache->enableCache();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the other hand this will not really be called in production.

The same is with the ContentSubgraphWithRuntimeCaches. it seems we never reenable the cache if marked once as stale (during event handling)

}

public function canHandle(EventInterface $event): bool
Expand Down
Expand Up @@ -36,14 +36,17 @@ final class WorkspaceRuntimeCache
*/
private array $cachedWorkspacesByContentStreamId = [];

public function enableCache(): void
{
$this->resetCache(true);
}

/**
* @return void
*/
public function disableCache(): void
{
$this->cacheEnabled = false;
$this->cachedWorkspacesByName = [];
$this->cachedWorkspacesByContentStreamId = [];
$this->resetCache(false);
}

public function getWorkspaceByName(WorkspaceName $name): ?Workspace
Expand Down Expand Up @@ -74,4 +77,14 @@ public function getByCurrentContentStreamId(ContentStreamId $contentStreamId): ?
}
return null;
}

/**
* @param bool $isEnabled if TRUE, the caches work; if FALSE, they do not store anything.
*/
private function resetCache(bool $isEnabled): void
{
$this->cacheEnabled = $isEnabled;
$this->cachedWorkspacesByName = [];
$this->cachedWorkspacesByContentStreamId = [];
}
}