Completed
Pull Request — master (#555)
by Jeroen De
03:53
created

CachingPageRetriever::fetchPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Infrastructure;
6
7
use Doctrine\Common\Cache\Cache;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class CachingPageRetriever implements PageRetriever {
14
15
	private $pageRetriever;
16
	private $cache;
17
18
	public function __construct( PageRetriever $pageRetriever, Cache $cache ) {
19
		$this->pageRetriever = $pageRetriever;
20
		$this->cache = $cache;
21
	}
22
23
	public function fetchPage( string $pageName, string $fetchMode ): string {
24
		if ( $this->cache->contains( $pageName ) ) {
25
			return $this->cache->fetch( $pageName );
26
		}
27
28
		$content = $this->pageRetriever->fetchPage( $pageName, $fetchMode );
29
30
		$this->cache->save( $pageName, $content );
31
32
		return $content;
33
	}
34
35
}
36