File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Flowpack \FullPageCache \Http ;
3+
4+ use Neos \Flow \Annotations as Flow ;
5+ use Neos \Cache \Frontend \StringFrontend ;
6+ use Neos \Flow \Http \Component \ComponentChain ;
7+ use Neos \Flow \Http \Component \ComponentContext ;
8+ use Neos \Flow \Http \Component \ComponentInterface ;
9+ use function GuzzleHttp \Psr7 \parse_response ;
10+
11+ /**
12+ *
13+ */
14+ class RequestInterceptorComponent implements ComponentInterface
15+ {
16+ /**
17+ * @Flow\Inject
18+ * @var StringFrontend
19+ */
20+ protected $ cacheFrontend ;
21+
22+ /**
23+ * @inheritDoc
24+ */
25+ public function handle (ComponentContext $ componentContext )
26+ {
27+ $ request = $ componentContext ->getHttpRequest ();
28+ if ($ request ->getMethod () !== 'GET ' ) {
29+ return ;
30+ }
31+
32+ if (!empty ($ request ->getUri ()->getQuery ())) {
33+ return ;
34+ }
35+
36+ $ entryIdentifier = md5 ((string )$ request ->getUri ());
37+
38+ $ entry = $ this ->cacheFrontend ->get ($ entryIdentifier );
39+ if ($ entry ) {
40+ $ response = parse_response ($ entry );
41+ $ response = $ response ->withHeader ('X-From-FullPageCache ' , $ entryIdentifier );
42+ $ componentContext ->replaceHttpResponse ($ response );
43+ $ componentContext ->setParameter (ComponentChain::class, 'cancel ' , true );
44+ }
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Flowpack \FullPageCache \Http ;
3+
4+ use Neos \Cache \Frontend \StringFrontend ;
5+ use Neos \Flow \Annotations as Flow ;
6+ use Neos \Flow \Http \Component \ComponentContext ;
7+ use Neos \Flow \Http \Component \ComponentInterface ;
8+ use function GuzzleHttp \Psr7 \str ;
9+
10+ /**
11+ *
12+ */
13+ class RequestStorageComponent implements ComponentInterface
14+ {
15+ /**
16+ * @Flow\Inject
17+ * @var StringFrontend
18+ */
19+ protected $ cacheFrontend ;
20+
21+ /**
22+ * @inheritDoc
23+ */
24+ public function handle (ComponentContext $ componentContext )
25+ {
26+ $ request = $ componentContext ->getHttpRequest ();
27+ if (strtoupper ($ request ->getMethod ()) !== 'GET ' ) {
28+ return ;
29+ }
30+
31+ if (!empty ($ request ->getUri ()->getQuery ())) {
32+ return ;
33+ }
34+
35+ $ response = $ componentContext ->getHttpResponse ();
36+
37+ if ($ response ->hasHeader ('X-From-FullPageCache ' )) {
38+ return ;
39+ }
40+
41+ $ entryIdentifier = md5 ((string )$ request ->getUri ());
42+
43+ $ modifiedResponse = $ response ->withHeader ('X-Storage-Component ' , $ entryIdentifier );
44+ $ this ->cacheFrontend ->set ($ entryIdentifier , str ($ modifiedResponse ));
45+ }
46+ }
47+
Original file line number Diff line number Diff line change 1+ Flowpack_FullPageCache_Entries :
2+ backend : Neos\Cache\Backend\RedisBackend
3+ backendOptions :
4+ port : 32772
Original file line number Diff line number Diff line change 1+ Flowpack\FullPageCache\Http\RequestInterceptorComponent :
2+ properties :
3+ cacheFrontend :
4+ object :
5+ factoryObjectName : Neos\Flow\Cache\CacheManager
6+ factoryMethodName : getCache
7+ arguments :
8+ 1 :
9+ value : Flowpack_FullPageCache_Entries
10+
11+ Flowpack\FullPageCache\Http\RequestStorageComponent :
12+ properties :
13+ cacheFrontend :
14+ object :
15+ factoryObjectName : Neos\Flow\Cache\CacheManager
16+ factoryMethodName : getCache
17+ arguments :
18+ 1 :
19+ value : Flowpack_FullPageCache_Entries
Original file line number Diff line number Diff line change 1+ Neos :
2+ Flow :
3+ http :
4+ chain :
5+ ' process ' :
6+ chain :
7+ requestInterceptor :
8+ position : ' start 999999'
9+ component : ' Flowpack\FullPageCache\Http\RequestInterceptorComponent'
10+ ' postprocess ' :
11+ chain :
12+ requestStorage :
13+ position : ' after standardsCompliance'
14+ component : ' Flowpack\FullPageCache\Http\RequestStorageComponent'
Original file line number Diff line number Diff line change 1+ Full Page Cache
2+ ===============
3+
4+ WIP,does not invalidate entries ever. Do not use yet!
Original file line number Diff line number Diff line change 1+ {
2+ "description" : " Does Page Cache THings" ,
3+ "type" : " neos-package" ,
4+ "name" : " flowpack/fullpagecache" ,
5+ "license" : " MIT" ,
6+ "require" : {
7+ "neos/neos" : " ^5.0 || dev-master"
8+ },
9+ "autoload" : {
10+ "psr-4" : {
11+ "Flowpack\\ FullPageCache\\ " : " Classes/"
12+ }
13+ },
14+ "extra" : {
15+ "neos" : {
16+ "package-key" : " Flowpack.FullPageCache"
17+ }
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments