Skip to content

Commit

Permalink
register CatchUpHook for flushing Subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
skurfuerst committed Sep 12, 2024
1 parent c8953e6 commit 66193dd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepositoryRegistry\SubgraphCachingInMemory;

use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
use Neos\EventStore\Model\EventEnvelope;

/**
* Ensures that the {@see SubgraphCachePool} is flushed always when content changes. This CatchUpHook
* is triggered when projections change.
*
* @internal
*/
#[Flow\Proxy(false)]
final class FlushSubgraphCachePoolCatchUpHook implements CatchUpHookInterface
{

public function __construct(private readonly SubgraphCachePool $subgraphCachePool)
{
}

public function onBeforeCatchUp(): void
{
}

public function onBeforeEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void
{
}

public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void
{
$this->subgraphCachePool->reset();
}

public function onBeforeBatchCompleted(): void
{
}

public function onAfterCatchUp(): void
{
$this->subgraphCachePool->reset();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepositoryRegistry\SubgraphCachingInMemory;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;

/**
* Factory for {@see FlushSubgraphCachePoolCatchUpHook}, auto-registered in Settings.yaml for GraphProjection
*
* @internal
*/
class FlushSubgraphCachePoolCatchUpHookFactory implements CatchUpHookFactoryInterface
{

public function __construct(
private readonly SubgraphCachePool $subgraphCachePool
) {
}
public function build(ContentRepository $contentRepository): CatchUpHookInterface
{
return new FlushSubgraphCachePoolCatchUpHook($this->subgraphCachePool);
}
}
4 changes: 4 additions & 0 deletions Neos.ContentRepositoryRegistry/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ Neos:
'Neos.ContentRepository:ContentGraph':
# NOTE: This introduces a soft-dependency to the neos/contentgraph-doctrinedbaladapter package, but it can be overridden when a different adapter is used
factoryObjectName: Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjectionFactory

catchUpHooks:
'Neos.ContentRepositoryRegistry:FlushSubgraphCachePool':
factoryObjectName: Neos\ContentRepositoryRegistry\SubgraphCachingInMemory\FlushSubgraphCachePoolCatchUpHookFactory

0 comments on commit 66193dd

Please sign in to comment.