MediaWikiCache::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SimpleCache\Cache;
4
5
use BagOStuff;
6
7
/**
8
 * Adapter around MediaWikis BagOStuff.
9
 *
10
 * @codeCoverageIgnore
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class MediaWikiCache implements Cache {
16
17
	protected $mediaWikiCache;
18
	protected $expiryTimeInSeconds;
19
20
	/**
21
	 * @param BagOStuff $mediaWikiCache
22
	 * @param int $expiryTimeInSeconds 0 for no expiry time
23
	 */
24
	public function __construct( BagOStuff $mediaWikiCache, $expiryTimeInSeconds = 0 ) {
25
		$this->mediaWikiCache = $mediaWikiCache;
26
		$this->expiryTimeInSeconds = $expiryTimeInSeconds;
27
	}
28
29
	public function get( $key ) {
30
		$value = $this->mediaWikiCache->get( $key );
31
32
		if ( $value === false ) {
33
			return null;
34
		}
35
36
		return $value;
37
	}
38
39
	public function has( $key ) {
40
		return $this->get( $key ) !== null;
41
	}
42
43
	public function set( $key, $value ) {
44
		$this->mediaWikiCache->set( $key, $value, $this->expiryTimeInSeconds );
45
	}
46
47
}
48