-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathContentCacheAspect.php
More file actions
58 lines (50 loc) · 1.63 KB
/
ContentCacheAspect.php
File metadata and controls
58 lines (50 loc) · 1.63 KB
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
<?php
namespace Flowpack\FullPageCache\Aspects;
use Neos\Cache\Frontend\StringFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Utility\Exception\PropertyNotAccessibleException;
use Neos\Utility\ObjectAccess;
#[Flow\Aspect]
#[Flow\Scope("singleton")]
class ContentCacheAspect
{
private bool $hadUncachedSegments = false;
/**
* @var StringFrontend
*/
#[Flow\Inject]
protected $cacheFrontend;
/**
* @Flow\Before("method(Neos\Fusion\Core\Cache\ContentCache->(createUncachedSegment)())")
*/
public function grabUncachedSegment(JoinPointInterface $joinPoint): void
{
$this->hadUncachedSegments = true;
}
/**
* @throws PropertyNotAccessibleException
*/
#[Flow\Before("method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->shutdownObject())")]
public function interceptNodeCacheFlush(JoinPointInterface $joinPoint): void
{
$object = $joinPoint->getProxy();
$tags = ObjectAccess::getProperty($object, 'tagsToFlush', true);
$tags = array_map([$this, 'sanitizeTag'],$tags);
$this->cacheFrontend->flushByTags($tags);
}
public function hasUncachedSegments(): bool
{
return $this->hadUncachedSegments;
}
/**
* Sanitizes the given tag for use with the cache framework
*
* @param string $tag A tag which possibly contains non-allowed characters, for example "NodeType_Acme.Com:Page"
* @return string A cleaned up tag, for example "NodeType_Acme_Com-Page"
*/
protected function sanitizeTag(string $tag): string
{
return strtr($tag, '.:', '_-');
}
}