-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
RouteCacheFlusher.php
91 lines (83 loc) · 2.6 KB
/
RouteCacheFlusher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Neos\Neos\Routing\Cache;
/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Routing\RouterCachingService;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\Workspace;
/**
* This service flushes Route caches triggered by node changes.
*
* @Flow\Scope("singleton")
*/
class RouteCacheFlusher
{
/**
* @Flow\Inject
* @var RouterCachingService
*/
protected $routeCachingService;
/**
* @var array
*/
protected $tagsToFlush = [];
/**
* Schedules flushing of the routing cache entries for the given $node
* Note that child nodes are flushed automatically because they are tagged with all parents.
*
* @param NodeInterface $node The node which has changed in some way
* @return void
*/
public function registerNodeChange(NodeInterface $node)
{
if (in_array($node->getIdentifier(), $this->tagsToFlush)) {
return;
}
if (!$node->getNodeType()->isOfType('Neos.Neos:Document')) {
return;
}
$this->tagsToFlush[] = $node->getIdentifier();
}
/**
* Schedules flushing of the all routing cache entries of the workspace whose base workspace has changed.
* In most cases $workspace will be a user's personal workspace. Flushing the respective cache entries guards
* against mismatches for nodes which exist in the old and the new base workspace but have different node
* identifiers and the same URI path (segment).
*
* @param Workspace $workspace
* @param Workspace|null $oldBaseWorkspace
* @param Workspace|null $newBaseWorkspace
* @return void
*/
public function registerBaseWorkspaceChange(Workspace $workspace, Workspace $oldBaseWorkspace = null, Workspace $newBaseWorkspace = null)
{
if (!in_array($workspace->getName(), $this->tagsToFlush)) {
$this->tagsToFlush[] = $workspace->getName();
}
}
/**
* Flush caches according to the previously registered node changes.
*
* @return void
*/
public function commit()
{
$this->routeCachingService->flushCachesByTags($this->tagsToFlush);
$this->tagsToFlush = [];
}
/**
* @return void
*/
public function shutdownObject()
{
$this->commit();
}
}